-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Compose cannot recreate a container on Swarm if the container has an host port mapping #2866
Comments
We discussed this a bit, and the only solution we have right now is to not set the |
I have one use case where I need both placement constraint and port mapping: my load balancers are using volumes for dynamic reconfiguration. Maybe Compose could do an indirection, i.e.:
(A similar plan is to create a dummy container to be used as an anchor for constraints; I think this is what was done in early Compose version to manage volumes.) We might also want to punt this to Swarm to change the way host port mappings are handled but that might provoke other breakage on their end! |
I find it a bit odd that Swarm considers a stopped container to be using the port. That pretty much breaks Compose's recreate logic, along with what seems like a generally reasonable use case outside of Compose (stop container A, start container A', remove container A). |
It is a bit unexpected at first, I added this note to the swarm docs a while ago to make it clear: https://docs.docker.com/swarm/scheduler/filter/#configure-the-available-filters:03285bdc704a53de2afbdd4c6c57e10d I think it's necessary though (at least with the current architecture). If you check constraints when starting the container (instead of creating it), then you'd end up with a ton of race conditions where multiple containers get created on a node, then one starts and all those containers now refuse to start because the constraints aren't valid anymore (the started container stole the resources). It would also be an issue with restart policies. |
That might require compose to be a lot more aware of swarm. It is possible that we could destroy the container before removing it. The problem with that approach is that if there is an error after we remove the original container, we completely lose track of the volumes that need to be applied to the new container (which is really bad). True, we could also re-introduce the intermediate container that we used before What if you were to use named volumes instead of the unnamed container volumes? If we did #2866 (comment) and you were able to use named volumes, I think it might work. |
We've implemented the discussed partial solution in #2894. This is still an issue, but only when using container volumes with exposed or host ports. Using named volumes or no volumes should work correctly. |
Thank you! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it had not recent activity during the stale period. |
What I have
What I do
With the following
docker-compose.yml
:I run:
What I expect to see
Container is created, then recreated.
What I see instead
Container is created, but when trying to recreate it, I see:
(Where
a0e3...
is the ID of the existing container.)Cause
Compose provides a placement constraint to force the new container to be on the same host as the old one. But when there is a port mapping, this fails, even if the container has been stopped first, because Swarm doesn't deal with port mappings the same way as Engine does (a stopped container is still considered to use the port).
I attached the logs of
docker inspect
(before recreating the container) and the verbose output ofdocker-compose up -d
.inspect.log.txt
compose.log.txt
The text was updated successfully, but these errors were encountered: