1
votes

I am new to Docker and I want to dockerise the Django app to run as a container. i have OSX 10.11.16 El Capitan with Docker Toolbox 19.03.01.

Here is the Dockerfile

FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

Here is docker-compose.yml conf

version: '3'

networks:
    mynetwork:
        driver: bridge

services:

  db:
    image: postgres
    ports:
      - "5432:5432"
    networks:
      - mynetwork
    environment:
      POSTGRES_USER: xxxxx
      POSTGRES_PASSWORD: xxxxx

  web:
    build: .
    networks:
      - mynetwork
  links:
      - db
    environment:
      SEQ_DB: cath_local
      SEQ_USER: xxxxx
      SEQ_PW: xxxxx
      PORT: 5432
      DATABASE_URL: postgres://xxxxx:xxxxx@db:5432/cath_local

    command: python manage.py runserver 0.0.0.0:8000

    volumes:
      - .:/code

    ports:
      - "8000:8000"

    depends_on:
      - db

well atthis point i run:

docker-compose up

but my postgreSQL db seem to start and stop without Errors, if i inspect db log in docker i get:

2019-09-17 03:29:37.296 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 2019-09-17 03:29:37.301 UTC [1] LOG: listening on IPv6 address "::", port 5432 2019-09-17 03:29:37.304 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2019-09-17 03:29:37.617 UTC [21] LOG: database system was shut down at 2019-09-17 03:28:33 UTC

2019-09-17 03:29:37.795 UTC [1] LOG: database system is ready to accept connections 2019-09-17 03:30:11.297 UTC [1] LOG: received smart shutdown request 2019-09-17 03:30:11.409 UTC [1] LOG: background worker "logical replication launcher" (PID 27) exited with exit code 1 2019-09-17 03:30:11.411 UTC [22] LOG: shutting down 2019-09-17 03:30:11.463 UTC [1] LOG: database system is shut down

Whi my postgreSQL does start and stop?

So many thanks in advance

1

1 Answers

1
votes

As per the documentation on the official Docker image of PostgreSQL here you need to add the restart parameter on your docker-compose.yaml for the database service.

When you perform the docker-compose up can see the database rebooting twice before remain stable, also you can add some volumes to your docker-compose.yaml to persist the data.

version: '3'

networks:
    mynetwork:
        driver: bridge

services:

  db:
    image: postgres
    restart: always
    ports:
      - "5432:5432"
    networks:
      - mynetwork
    environment:
      POSTGRES_USER: xxxxx
      POSTGRES_PASSWORD: xxxxx
    volumes:
      - ./data:/var/lib/postgresql/data

  web:
    build: .
    networks:
      - mynetwork
  links:
      - db
    environment:
      SEQ_DB: cath_local
      SEQ_USER: xxxxx
      SEQ_PW: xxxxx
      PORT: 5432
      DATABASE_URL: postgres://xxxxx:xxxxx@db:5432/cath_local

    command: python manage.py runserver 0.0.0.0:8000

    volumes:
      - .:/code

    ports:
      - "8000:8000"

    depends_on:
      - db