I thought about building a Django environment with Docker by referring to the following, but it got stuck a little, so I will leave it as a memo. https://docs.docker.jp/compose/django.html
When I used docker-compose up -d for container startup, only the DB container did not start up properly ...
toruchan:~/work/py-work$ docker-compose up -d
Starting pywork_db_1 ...
Starting pywork_db_1 ... done
Creating pywork_web_1 ...
Creating pywork_web_1 ... done
toruchan:~/work/py-work$ docker-compose ps
    Name                  Command               State            Ports
-------------------------------------------------------------------------------
pywork_db_1    docker-entrypoint.sh postgres    Exit 1
pywork_web_1   python3 manage.py runserve ...   Up       0.0.0.0:8000->8000/tcp
toruchan:~/work/py-work$ docker-compose logs
Attaching to pywork_web_1, pywork_db_1
db_1   | Error: Database is uninitialized and superuser password is not specified.
db_1   |        You must specify POSTGRES_PASSWORD to a non-empty value for the
db_1   |        superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
db_1   |
db_1   |        You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
db_1   |        connections without a password. This is *not* recommended.
db_1   |
db_1   |        See PostgreSQL documentation about "trust":
db_1   |        https://www.postgresql.org/docs/current/auth-trust.html
db_1   | Error: Database is uninitialized and superuser password is not specified.
db_1   |        You must specify POSTGRES_PASSWORD to a non-empty value for the
db_1   |        superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
db_1   |
db_1   |        You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
db_1   |        connections without a password. This is *not* recommended.
db_1   |
db_1   |        See PostgreSQL documentation about "trust":
db_1   |        https://www.postgresql.org/docs/current/auth-trust.html
Apparently an error will occur if the password is not set ...?
Then I came up with the following two
I just want to launch it in the local environment for the time being, so select 1 password invalidation
Add a line of POSTGRES_HOST_AUTH_METHOD:'trust' to the docker-compose.yml file as a countermeasure for case 1.
As a whole, it looks like this
version: '3'
services:
  db:
    image: postgres
    environment:
      POSTGRES_HOST_AUTH_METHOD: 'trust'
  web:
    build: .
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db
I should have restarted the container with this I will set the password properly later ...
Recommended Posts