Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker compose restart/stop <service> should have an option to affect service's container only #9044

Closed
lephuongbg opened this issue Dec 16, 2021 · 4 comments

Comments

@lephuongbg
Copy link

Description

Disclaimer: I think the major change in behavior might be intentionally done but in that case, there should be an option to use docker-compose v1's behavior.

In docker-compose v1, when you use docker-compose restart <service name>, only the service's container(s) is restarted. Other containers that are created by docker-compose run are not affected.

In docker compose v2, when you use docker compose restart <service name>, all containers that are related to the service are restarted. There might be many containers that were created by docker compose run <service> [command] that shouldn't be restarted or stopped with the service's container. I don't see any option in the command help that could do that.

Output of docker compose version:

Docker Compose version v2.1.1
@ndeloof
Copy link
Contributor

ndeloof commented Dec 16, 2021

I assume you have services with depends_on (or other relationship) with the service you want to restart?
Could you maybe provide a minimal reproduction scenario so we can debate this is expected or not?

@lephuongbg
Copy link
Author

Let's have a simple example compose file:

services:
  web:
    image: nginx
  1. On one terminal, I run docker compose up to start the web service.
  2. On another terminal, I run docker compose run web bash to have a shell prompt to work with.
  3. Now after updating some config, I would restart the web service by docker compose restart web.

Behavior of docker-compose v1: Only the container started in step 1 is restarted.
Behavior of docker-compose v2: Both the containers started in step 1 and step 2 are restarted.

The behavior of v2 can be problematic when I have lots of stopped docker-compose run containers lying around. All of them get started again uncontrollably. My use case is local development, so I (and also IDE) tend to use docker-compose run a lot. The --rm flag is nice but containers do not get removed reliably.

@ndeloof
Copy link
Contributor

ndeloof commented Dec 17, 2021

docker compose run web bash doesn't affect the service, it run another "ont off" container aside the service container. But I assume in your example you're using this to edit some config file mounted as volumes?

docker compose restart should not affect one-off containers (this is definitively a bug)

@lephuongbg
Copy link
Author

docker compose restart should not affect one-off containers (this is definitively a bug)

I'd like to add more on this is that not only restart, stop and start on v2 are also affecting one-off containers too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants