skip to Main Content

I wish to expand a web-application using docker (I’m beginner in Docker). My application demands PostgreSQL. Therefore I decided to use the docker-compose.

The docker-compose.yaml looks like:

version: '3.8'

services: 
    db:
        image: postgres
        command: "postgres -c listen_addresses='*'"
        environment:
            - POSTGRES_DB=CatsQMS
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=12345qwerty

    application:
        build: .
        ports:
            - "8080:8080"
        depends_on:
            - db

Also I have the file config.yaml which configures my web-application, it looks like this:

database_config:
  host: db
  user: postgres
  password: 12345qwerty
  port: 5432
  database: CatsQMS

# Unimportant stuff

And when I lunch the docker-compose, using docker-compose up the build is freezing at this point:

Recreating cats_queue_management_system_db_1 ... done
Recreating cats_queue_management_system_application_1 ... done
Attaching to cats_queue_management_system_db_1, cats_queue_management_system_application_1
db_1           |
db_1           | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1           |
db_1           | 2020-05-20 13:42:51.628 UTC [1] LOG:  starting PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1           | 2020-05-20 13:42:51.628 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1           | 2020-05-20 13:42:51.628 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1           | 2020-05-20 13:42:51.635 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1           | 2020-05-20 13:42:51.660 UTC [24] LOG:  database system was shut down at 2020-05-20 13:39:45 UTC
db_1           | 2020-05-20 13:42:51.673 UTC [1] LOG:  database system is ready to accept connections

Perhaps it’s an important thing, my Dockerfile:

FROM python:3.8

RUN mkdir /docker-entrypoint-initdb.d/

COPY ./application/sources/database/init.sql /docker-entrypoint-initdb.d/

RUN mkdir /app

WORKDIR /app

COPY . /app

RUN pip install -r requirements.txt

RUN python3 setup.py develop

ENTRYPOINT ["start_app", "-d"]

Where have I admitted a mistake?

3

Answers


  1. I don’t think the issue is with the database container. It looks like it starts up normally and is listening for connections.

    What is the ENTRYPOINT in your Dockerfile executing, “start_app”?

    The -d argument looks like it may be starting the website as a daemon (background process) which doesn’t give docker a process to hook into.

    Maybe try
    ENTRYPOINT [“start_app”]

    Login or Signup to reply.
  2. Your application and PostgreSQL database are running and should work as expected. But Docker attached after running the containers to the db container.

    You can avoid this by using the option -d or --detach on docker-compose up:

    The docker-compose up command aggregates the output of each container (essentially running docker-compose logs -f). When the command exits, all containers are stopped. Running docker-compose up -d starts the containers in the background and leaves them running.

    So your command looks like this:

    docker-compose up -d
    
    Login or Signup to reply.
  3. Is the issue that your web app cant talk to the database? If so it might be that a) they don’t share a network, and b) you’re trying to connect on port 5432, but the postgres db container is not exposing or publishing this port.

    I’ve added a few things to your docker-compose file that might make it work…

    version: '3.8'
    
    networks:
        test:
    
    services: 
        db:
            image: postgres
            command: "postgres -c listen_addresses='*'"
            environment:
                - POSTGRES_DB=CatsQMS
                - POSTGRES_USER=postgres
                - POSTGRES_PASSWORD=12345qwerty
            ports:
                - 5432:5432
            networks:
                - test
    
        application:
            build: .
            ports:
                - 8080:8080
            networks:
                - test
            depends_on:
                - db
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search