docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
33.78k stars 5.2k forks source link

Compose cannot recreate a container on Swarm if the container has a host port mapping and uses volumes_from #3453

Closed rmelick closed 5 years ago

rmelick commented 8 years ago

This is basically the same issue as #2866 (which was fixed in #2894). I was hoping that using volumes_from would allow the container to be successfully recreated, but that seems to not be the case.

What I Have

Full project is available on github: https://github.com/rmelick/docker-compose-up

Docker Versions

I have two example images.

The data-container, which contains a volume that will be mounted by the app container using volumes_from

FROM alpine:3.3
RUN rm -f "/environment-conf"
RUN mkdir "/environment-conf"
COPY . /environment-conf
VOLUME ["/environment-conf"]
CMD ["tail", "-f", "/dev/null"]

The app-container

FROM alpine:3.3
ENV cacheBust 2
CMD ["tail", "-f", "/dev/null"]

What I Do

With the following docker-compose file (also available at https://github.com/rmelick/docker-compose-up/blob/master/docker-compose.yml)

version: '2'
services:
  app:
    image: rmelick/docker-compose-up-app-container:latest
    hostname: app
    container_name: app
    ports:
     - "10080:10080"
    volumes_from:
      - appConfig:ro
    environment:
      - "constraint:node==docker-compose-up-node"
  appConfig:
    image: rmelick/docker-compose-up-data-container:latest
    environment:
      - "constraint:node==docker-compose-up-node"

I run the following

eval $(docker-machine env --swarm docker-compose-up-master)
docker-compose up -d
docker-compose up -d --force-recreate

What I Expected

I expected the app container to be recreated successfully

What Happened Instead

I saw the following error

rmelick@rmelick-ld:~/src/other/docker-compose-up$ docker-compose up -d --force-recreate
Recreating dockercomposeup_appConfig_1
Recreating app
ERROR: Unable to find a node that satisfies the following conditions 
[port 10080 (Bridge mode)]
[available container slots]
[--volumes-from=c1819375f073a25a6056ef208b081e697111dd9d0e53953fd6af99ec65044275:ro]

The full log from a different run with --verbose is attached: docker-compose-log.txt

Question

The comments in #2866 and #2894 implied this failure would happen if my app container had volumes that needed to be copied over to its replacement instance during the --force-recreate. But, the only volume it's using is the read only volume supplied by the data container. It would be totally ok to recreate my app container without copying any volumes, right?

dnephin commented 8 years ago

volumes_from still forces the container to be scheduled on the same node (this is enforced by swarm), so I don't expect it to work.

villasenor commented 6 years ago

Note that this is not an issue with compose, it's an issue with swarm. Volumes referenced need to be on the same node. Often this is because swarm can't schedule all of the required volumes (and their respective containers) on the same node due to capacity issues, and therefore can't fulfill the volumes_from request.