Docker Community Forums

Share and learn in the Docker community.

One of the postgres containers stops as soon as it starts

I’m currently working in a big app wich has a parent forlder with the docker.compose files calling other docker-compose files in sub folders which are the different modules of the app.
Everithing works everywhere but in my mac i started having an issue trying to intsall everything. One of the containers is exiting as soon it starts when i run docker-compose up -d in the parent folder. They are 9 containers but only 8 remain running. The one stopping is one of the postgres containers.
It’s not the code, since it works in other computers including my laptop at work and i cannot modify it since it propably would affect the rest of the team, and by the way this wasn’t happening in my mac, it started now.
Any Idea where to begin?

It is difficult to have ideas if we don’t have more detailed information about how you create this container. A good point to start is the log of the exited container. If you use the Postgres image from Dockerhub you can read it with:

docker container logs CONTAINER_ID

(type the first 4 or 5 characters of the ID)

Have you anywhere specified the m/m limitation? I had the similar issue when i used to run oracle database.

I am new to docker, your comment saved me lots of trouble. In my case, I had to insert “-e POSTGRES_HOST_AUTH_METHOD=trust” option in “docker run” command. (I am just testing the sample-voting-app), so I guess security is not a concern for me at this time. But your comment solved my issue. Thanks.

After researching some more, I found the answer in part also by finding clues on Stackoverflow.

Anyway, I modified my script to look like this :

/opt/edb/9.5AS/bin/pg_ctl start -D /opt/edb/9.5AS/data exec
And the Dockerfile now ends like below :

USER enterprisedb
ENTRYPOINT ["/opt/edb/9.5AS/bin/"]
CMD ["/bin/bash"]
The core of the solution is the last line in the script as well as the last line in the Dockerfile. Both combined make it so that once the DB started, a new shell (/bin/bash) gets started. This will run in the foreground, thus keeping the Container alive. By starting the container in detached mode, it now does exactly what we need it to do.