0

I have a docker-compose.yml configured to create and add data to a database. My compose file then loads in a bash script which will run a few short tests on the data and exit 1 upon a test failing. This is working as intended, however when I want my container to exit upon all tests passing but the docker-entrypoint.sh script seems to ignore my exit 0 command. I've attempted to write a different entrypoint script which will call on the docker-entrypoint.sh in hopes that I can then exit the container, but I'm not having any luck. Is there any easy way to implement this?

Output example:

postgres_1  | PostgreSQL init process complete; ready for start up.
postgres_1  |
postgres_1  | 2020-04-06 19:29:58.511 UTC [1] LOG:  starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1  | 2020-04-06 19:29:58.511 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1  | 2020-04-06 19:29:58.511 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1  | 2020-04-06 19:29:58.517 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1  | 2020-04-06 19:29:58.534 UTC [102] LOG:  database system was shut down at 2020-04-06 19:29:58 UTC
postgres_1  | 2020-04-06 19:29:58.540 UTC [1] LOG:  database system is ready to accept connections
2
  • 1
    Are there other things running in the container? The container won't exit until all the processes in it have died. Commented Apr 6, 2020 at 19:24
  • see my edit - it just says the database system is ready to accept connections. I want it to just close out upon all my tests passing. Commented Apr 6, 2020 at 19:31

1 Answer 1

1

it's normal; entrypoint will ignore any command , to solve this you can use CDM parameter after entrypoint declaration in Dockerfile. For example, the following snippet in Dockerfile

ENTRYPOINT ["/bin/echo", "Hello"]
CMD ["world"]

when container runs as

docker run -it <image> 

will produce output:

Hello world

but when container runs as

docker run -it <image> John

will result in:

Hello John

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the response. So in my instance, when would I want to exit to make sure the docker-entrypoint.sh script can exit at the right time?
for manual exit can use this method , if you want to do something after somethings should write bash script for that in entrypoint. @Polyphase29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.