Skip to content

Django project does not work when I try to put it into a Docker-Compose container #2340

@Valten1992

Description

@Valten1992

I am attempting to setup a Django project I made in eclipse in Docker-Compose for deployment purposes.

I copied my project into a directory just for Docker and followed a variety of tutorials online and from my understanding, the only services my App requires in Docker are Django and Postgres. Here is my docker-compose.yml file:

db:
  image: postgres:latest
  ports:
    - "5432"
  environment:
    POSTGRES_PASSWORD: postgres
    POSTGRES_USER: postgres
web:
  build: .
  ports:
   - "8000:8000"
  volumes:
   - .:/code
  links:
   - db
  command: python3 manage.py runserver 0.0.0.0:8000

and my DockerFile:

FROM python:3

#ENV LANG C.UTF-8
#RUN export LC_ALL="en_US.UTF-8"

RUN mkdir /code

WORKDIR /code

#Add requirements.txt to code
ADD requirements.txt /code/

RUN pip install -r requirements.txt

ADD . /code/

I have tested the python command locally in my virtualenv and the server starts, however, when I run 'docker-compose up' in the folder the application is located in, I get this output:

Creating hpr_db_1
Creating hpr_web_1
Attaching to hpr_db_1, hpr_web_1
db_1  | The files belonging to this database system will be owned by user "postgres".
db_1  | This user must also own the server process.
db_1  | 
db_1  | The database cluster will be initialized with locale "en_US.utf8".
db_1  | The default database encoding has accordingly been set to "UTF8".
db_1  | The default text search configuration will be set to "english".
db_1  | 
db_1  | Data page checksums are disabled.
db_1  | 
db_1  | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1  | creating subdirectories ... ok
db_1  | selecting default max_connections ... 100
db_1  | selecting default shared_buffers ... 128MB
db_1  | selecting dynamic shared memory implementation ... posix
db_1  | creating configuration files ... ok
db_1  | creating template1 database in /var/lib/postgresql/data/base/1 ... ok
db_1  | initializing pg_authid ... ok
db_1  | initializing dependencies ... ok
web_1 | /usr/local/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
web_1 |   return f(*args, **kwds)
web_1 | 
db_1  | creating system views ... ok
db_1  | loading system objects' descriptions ... ok
db_1  | creating collations ... ok
db_1  | creating conversions ... ok
db_1  | creating dictionaries ... ok
db_1  | setting privileges on built-in objects ... ok
db_1  | creating information schema ... ok
db_1  | loading PL/pgSQL server-side language ... ok
web_1 | /usr/local/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
web_1 |   return f(*args, **kwds)
web_1 | 
db_1  | vacuuming database template1 ... ok
db_1  | copying template1 to template0 ... ok
db_1  | copying template1 to postgres ... ok
db_1  | syncing data to disk ... ok
db_1  | 
db_1  | Success. You can now start the database server using:
db_1  | 
db_1  |     postgres -D /var/lib/postgresql/data
db_1  | or
db_1  |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1  | 
db_1  | 
db_1  | WARNING: enabling "trust" authentication for local connections
db_1  | You can change this by editing pg_hba.conf or using the option -A, or
db_1  | --auth-local and --auth-host, the next time you run initdb.
db_1  | waiting for server to start....LOG:  database system was shut down at 2015-11-06 15:18:39 UTC
db_1  | LOG:  MultiXact member wraparound protections are now enabled
db_1  | LOG:  autovacuum launcher started
db_1  | LOG:  database system is ready to accept connections
db_1  |  done
db_1  | server started
db_1  | ALTER ROLE
db_1  | 
db_1  | 
db_1  | /docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1  | 
db_1  | LOG:  received fast shutdown request
db_1  | LOG:  aborting any active transactions
db_1  | LOG:  autovacuum launcher shutting down
db_1  | waiting for server to shut down....LOG:  shutting down
db_1  | LOG:  database system is shut down
db_1  |  done
db_1  | server stopped
db_1  | 
db_1  | PostgreSQL init process complete; ready for start up.
db_1  | 
db_1  | LOG:  database system was shut down at 2015-11-06 15:18:41 UTC
db_1  | LOG:  MultiXact member wraparound protections are now enabled
db_1  | LOG:  database system is ready to accept connections
db_1  | LOG:  autovacuum launcher started

No message about the server starting or anything like that, I thunk its compiling my code due to the warning messages about deprecation I get when I run the application locally but I am quite stumped here. Can anyone see my error?

Upon closer inspection and changing the port for the Django server, I find that accessing the webpage returns a "Connection to the Server was reset while the page was loading" error. This indicates that something is being set up on that page. But I still cannot access it. I know Docker-Compose is working as simple Django applications from tutorials work just fine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions