Docker Compose with one Terminating Container
Asked Answered
F

2

8

I'm having a docker compose setup of a database container, an application container and one container which pre-loads the database with necessary data.

I want to start all of the containers together with docker-compose up while the pre-loading container terminates after it has completed it work with exit 0.

But terminating this one container takes down the complete setup with the message:

composesetup_load_1 exited with code 0
Gracefully stopping... (press Ctrl+C again to force)
Stopping composesetup_app_1...
Stopping composesetup_db_1...

Is there any way of having multiple containers with different life-time in one docker-compose setup? If yes, how?

Feune answered 12/6, 2015 at 20:40 Comment(0)
F
8

My workaround for now is to keep the pre-loading container running by adding tail -f /dev/null to the end of the entrypoint script. This keeps the process running, while nothing actual happens.

Feune answered 23/6, 2015 at 11:8 Comment(3)
Is this a common method of doing this sort of thing? Is there a "right" / "official" way to do this? I love this slick solution, in either case.Pandurate
This, so much. ThanksFeinstein
Clever, but it'd be better to sleep infFlense
N
-1

Using -d option at docker-compose up -d will run the process in detached mode. This avoids the need to kill the service with Ctrl+C and therefore stop the containers.

Note: I am asumming you killed the process with Ctrl+C from the message "Gracefully stopping... (press Ctrl+C again to force)" you shared.

Newfangled answered 31/7, 2017 at 16:3 Comment(3)
No, I've not terminated the process with Ctrl+C the process has just completed its work and thus terminates with exit 0. So running docker-compose with the -d option is no solution.Feune
@white_gecko, ok, thanks for clarifying. The behaviour is then as if the flag --abort-on-container-exit was set?Newfangled
Ok, maybe this flag is a solution … when I've posted the question at least this behavior was default.Feune

© 2022 - 2024 — McMap. All rights reserved.