Docker Community Forums

Share and learn in the Docker community.

Docker in Django 2.0 and Postgresql not working (Windows 10 Home)


(Ralfillo) #1

I’ve been following this tutorial and I made some modifications, because I’m using virtualenv instead of pipenv, so I’ll be using a requirements.txt file to manage the dependencies.

It’s the first time that I’m trying a project with Docker.

https://wsvincent.com/django-docker-postgresql/

Dockerfile:

# Pull base image
FROM python:3.6-slim

# Set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Install dependencies
RUN pip install --upgrade pip
ADD requirements.txt /code/
RUN pip install -r requirements.txt

# Copy project
COPY . /code/

docker-compsose.yml:

version: '3.6'

services:
  db:
    image: postgres:10.1-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
  web:
    build: .
    command: python /code/manage.py migrate --noinput
    command: python /code/manage.py runserver 0.0.0.0:8000
    volumes:
      - /code
    ports:
      - 8000:8000
    environment:
      - SECRET_KEY=changemeinprod
    depends_on:
      - db

volumes:
  postgres_data:

After running:

docker-compose up -d --build

And:

docker-compose up

Now it seems to be up and running but when I visit 127.0.0.1:8000 the site isn’t up.

The log:

(env) C:\Projects\dfb_mb_docker>docker-compose up
dfbmbdocker_db_1 is up-to-date
dfbmbdocker_web_1 is up-to-date
Attaching to dfbmbdocker_db_1, dfbmbdocker_web_1
db_1 | 2018-07-18 15:36:00.729 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
db_1 | 2018-07-18 15:36:00.730 UTC [1] LOG: listening on IPv6 address “::”, port 5432
db_1 | 2018-07-18 15:36:00.759 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2018-07-18 15:36:00.832 UTC [17] LOG: database system was shut down at 2018-07-18 15:21:50 UTC
db_1 | 2018-07-18 15:36:00.846 UTC [1] LOG: database system is ready to accept connections
db_1 | 2018-07-18 15:37:02.431 UTC [1] LOG: received smart shutdown request
db_1 | 2018-07-18 15:37:02.443 UTC [1] LOG: worker process: logical replication launcher (PID 23) exited with exit code 1
db_1 | 2018-07-18 15:37:02.444 UTC [18] LOG: shutting down
db_1 | 2018-07-18 15:37:02.514 UTC [1] LOG: database system is shut down
db_1 | 2018-07-18 15:37:14.596 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
db_1 | 2018-07-18 15:37:14.596 UTC [1] LOG: listening on IPv6 address “::”, port 5432
db_1 | 2018-07-18 15:37:14.626 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2018-07-18 15:37:14.683 UTC [17] LOG: database system was shut down at 2018-07-18 15:37:02 UTC
db_1 | 2018-07-18 15:37:14.696 UTC [1] LOG: database system is ready to accept connections
db_1 | 2018-07-18 15:38:36.294 UTC [1] LOG: received smart shutdown request
db_1 | 2018-07-18 15:38:36.305 UTC [1] LOG: worker process: logical replication launcher (PID 23) exited with exit code 1
db_1 | 2018-07-18 15:38:36.306 UTC [18] LOG: shutting down
db_1 | 2018-07-18 15:38:36.393 UTC [1] LOG: database system is shut down
db_1 | 2018-07-18 15:40:01.343 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
db_1 | 2018-07-18 15:40:01.343 UTC [1] LOG: listening on IPv6 address “::”, port 5432
db_1 | 2018-07-18 15:40:01.367 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2018-07-18 15:40:01.459 UTC [17] LOG: database system was shut down at 2018-07-18 15:38:36 UTC
db_1 | 2018-07-18 15:40:01.473 UTC [1] LOG: database system is ready to accept connections
db_1 | 2018-07-18 15:42:16.717 UTC [1] LOG: received smart shutdown request
db_1 | 2018-07-18 15:42:16.740 UTC [1] LOG: worker process: logical replication launcher (PID 23) exited with exit code 1
db_1 | 2018-07-18 15:42:16.741 UTC [18] LOG: shutting down
db_1 | 2018-07-18 15:42:16.816 UTC [1] LOG: database system is shut down
db_1 | 2018-07-18 15:42:40.411 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
db_1 | 2018-07-18 15:42:40.411 UTC [1] LOG: listening on IPv6 address “::”, port 5432
db_1 | 2018-07-18 15:42:40.429 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2018-07-18 15:42:40.495 UTC [17] LOG: database system was shut down at 2018-07-18 15:42:16 UTC
db_1 | 2018-07-18 15:42:40.505 UTC [1] LOG: database system is ready to accept connections
web_1 | /usr/local/lib/python3.6/site-packages/psycopg2/init.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in
order to keep installing from binary please use “pip install psycopg2-binary” instead. For details see: initd
ary-install-from-pypi>.
web_1 | “”")
web_1 | /usr/local/lib/python3.6/site-packages/psycopg2/init.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in
order to keep installing from binary please use “pip install psycopg2-binary” instead. For details see: nitd.psycopg/docs/install.html
ary-install-from-pypi>.
web_1 | “”")
web_1 | Performing system checks…
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | July 18, 2018 - 16:08:39
web_1 | Django version 2.0.6, using settings ‘dfb_mb.settings’
web_1 | Starting development server at 0.0.0.0:8000
web_1 | Quit the server with CONTROL-C.

There’s no errors and it looks like the app is live, but I can see the website in Chrome. Could you please help me out.

I appreciate your help!