Postgres shuts down immediately when started with docker-compose Postgres shuts down immediately when started with docker-compose postgresql postgresql

Postgres shuts down immediately when started with docker-compose


If you look at your log output, the following lines appear towards the end:

local-postgres9.5 | server stoppedlocal-postgres9.5 |local-postgres9.5 | PostgreSQL init process complete; ready for start up.

Apparently, stopping and restarting the Postgres server is part of the initialisation process. In fact, the second-to-last line says

local-postgres9.5 | LOG:  database system is ready to accept connections.


I tried your docker-compose and the service seems running in the container:

root@0afe99de0f0b:/# ps auxUSER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMANDpostgres     1  0.5  0.8 227148 16128 ?        Ss   14:42   0:00 postgrespostgres    74  0.0  0.0 227148  1768 ?        Ss   14:42   0:00 postgres: checkpointer process  postgres    75  0.0  0.0 227148  1772 ?        Ss   14:42   0:00 postgres: writer process  postgres    76  0.0  0.0 227148  1768 ?        Ss   14:42   0:00 postgres: wal writer process  postgres    77  0.0  0.1 227576  2720 ?        Ss   14:42   0:00 postgres: autovacuum launcher process  postgres    78  0.0  0.0  82132  1888 ?        Ss   14:42   0:00 postgres: stats collector process  root        79  2.0  0.0  21820  1984 ?        Ss   14:42   0:00 /bin/bashroot        84  0.0  0.0  19092  1296 ?        R+   14:42   0:00 ps aux

Anyway, for my project I use another image for postgresql: https://github.com/sameersbn/docker-postgresql. This one works fine.


Add password under postgres service in docker-compose.yml as given in the screenshot. Thank you.click to see the screenshot

version: '3'services:     postgres:          image: postgres          environment:              - POSTGRES_PASSWORD=postgres_password