Postgres environment construction with Docker I struggled a little, so note

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

  1. Disable password setting
  2. Set password

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

Postgres environment construction with Docker I struggled a little, so note
Data science environment construction with Docker
I made a development environment for Django 3.0 with Docker, Docker-compose, Poetry
LaTeX and R (a little Python) environment construction with SublimeText3 (Windows)
I touched "Orator" so I made a note
Get a local DynamoDB environment with Docker
[Linux] Build a jenkins environment with Docker
A memo packed with RADEX environment construction
[Linux] Build a Docker environment with Amazon Linux 2
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]
I was addicted to trying Cython with PyCharm, so make a note
Note: Prepare the environment of CmdStanPy with docker
Analytical environment construction with Docker (jupyter notebook + PostgreSQL)
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Environment construction: GCP + Docker
I made a ready-to-use syslog server with Play with Docker
[Python] OpenCV environment construction with Docker (cv2.imshow () also works)
Repairing a broken development environment with mavericks migration (Note)
From Kafka to KSQL --Easy environment construction with docker
I made a Python3 environment on Ubuntu with direnv.
[Go + Gin] I tried to build a Docker environment
Pepper-kun remote control environment construction with Docker + IPython Notebook
Build a development environment with Poetry Django Docker Pycharm
Build a Django development environment with Docker! (Docker-compose / Django / postgreSQL / nginx)
[Memo] Build a development environment for Django + Nuxt.js with Docker
I want to start a jupyter environment with one command
[Django] Build a Django container (Docker) development environment quickly with PyCharm
Create a simple Python development environment with VSCode & Docker Desktop
I just built a virtual environment with AWS lambda layer
ML environment construction with Miniconda
Docker + Django + React environment construction
Prepare python3 environment with Docker
A little stuck with chainer
[Python] I tried to implement stable sorting, so make a note
A note I was addicted to when creating a table with SQLAlchemy
(Note) Notes on building TensorFlow + Flask + Nginx environment with Docker Compose
Create a development environment for Go + MySQL + nginx with Docker (docker-compose)
Homework was a pain, so I do management accounting with Python
I made a segment tree with python, so I will introduce it
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
Create a simple Python development environment with VS Code and Docker
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
Neat, whose employment has been postponed to Corona, has started Docker, so I will leave a personal note.
I got stuck trying to install various things with Mac El captain pip, so make a note
Building a kubernetes environment with ansible 2
Get started with Python! ~ ① Environment construction ~
ruby environment construction with aws EC2
Build a go environment using Docker
Creating a Flask server with Docker
Build a deb file with Docker
I checked Mac Python environment construction
Build Mysql + Python environment with docker
Deploy a Django application with Docker
Easy Jupyter environment construction with Cloud9
Create a virtual environment with Python!
I made a fortune with Python.
Build PyPy execution environment with Docker
[Linux] Docker environment construction on Redhat
Automate environment construction with Shell Script
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)
Using Chainer with CentOS7 [Environment construction]