compose: Volume defined using volumes_from is not updated when stopping, recreating and starting the source service

I have defined volumes in a compose file like this:

version: '2'
services:
    nginx:
        ...
        volumes_from:
            - web

    web:
        ...
        volumes:
            - /var/www/myapp/static

The nginx container is configured to serve static files from the volume it gets from the web container. All other requests are proxied to the app running in the web container.

Getting things up and running using docker-compose up works just fine. However the problem starts when I restart the running web containers.

To have as little downtime as possible, I want to update the running web containers to the latest versions of my image, and recreate and restart them without having to do docker-compose down and docker-compose up. So I do:

$ docker-compose pull web
$ docker-compose stop web
$ docker-compose rm -f web
$ docker-compose start web

This makes sure only the web containers are downed, and the nginx container can keep running and accepting requests and proxy requests to other containers.

And even though static files in the defined volumes have changed, they are not updated in the nginx container.

Basically what I need is the volumes defined in volumes_from to be re-attached or re-created when the source container is recreated. Is that possible?

Versions

$ docker --version
Docker version 1.10.3, build 20f81dd
$ docker-compose --version
docker-compose version 1.6.2, build 4d72027

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 23

Most upvoted comments

@euri16 how far did you get? I ended up ding rsync which worked perfectly.

@aanand’s solution doesn’t work for me still. When I update one data container, the named volume doesn’t update to latest data.

Update 1: Did some googling and ended up copying data from data_container:/data to data_container:/volume.

Update 2: For some reason command: cp -rf /widget/* /var/www/html/ in docker-compose returns “no such file or directory” error. But CMD cp -rf /widget/* /var/www/html/ in Dockerfile works fine. Not sure what is going. I hope this helps someone.

Was there any good solution to this? Is using a named volume best option as @aanand suggests?

Same here. Specifically, I have a Dockerfile that exposes a volume:

...
VOLUME /var/www/api

and a docker-compose.yml that brings it all together:

symfony:
  build: ./symfony

fpm:
  build: ./fpm
  volumes_from:
    - symfony
  ports:
    - "9000:9000"

nginx:
  build: ./nginx
  volumes_from:
    - symfony
  ports:
    - "80:80"
    - "443:443"
  links:
    - fpm

However, after updating any of the files in the volume container the nginx and fpm containers see the “old” version of those files.

What I’m expecting is that whenever I update files in the volume container and recreate it, the changes will be reflected in the conatiners connected to it without recreating them.

I’m having the same problem with similar versions of docker-compose and docker daemon.

I did some debugging via docker events and found that compose actually somehow reuses the volumes as mentioned on #1981 . I certainly don’t agree much with the decision but what I did was instead of mounting the static folder directly through the docker-compose.yml I mounted a /static folder and inside my entrypoint, right after I generate all static files inside the /var/www/myapp/static folder, I move them to the /static folder and they get updated as expected.

It’s a kida dirty workaround, but it works…for while…in production…