Compose: Update Data in Named Volume Upon Remount

Created on 18 Jun 2017  路  7Comments  路  Source: docker/compose

I have a quick question about named volumes, and how to update data within it.

Basically my continuous integration system builds a docker image and as a step in the build copies the latest version of my code into it. From there it pushes that image to a private registry then once that is done I issue an SSH command on my server running docker-compose to docker-compose pull && docker-compose up -d.

Where the problem is, is I have multiple services that share data from that one docker image I just created and pulled, my configuration of named volumes looks like this:

version: '3'
services:
  service1:
    image: imageWithUpdatedCode
    volumes:
      - app:/var/www

  service2:
    image: someImage
    volumes:
      - app:/var/www

volumes:
  app:

So, when I update the image that service1 is using, because the volume app already exists, it doesn't update the volume with the new code found in service1's new docker image.

I know that I can issue a command on startup of the container to copy in the new data from another directory, but that seems like a bit of a hack to me. Is there a better way to update the data in the app volume?

arevolumes formav3 kinquestion stale

Most helpful comment

Any news around this issue?. We are facing the same issue with both volumes_from & named volumes. They don't get updated at service update.

All 7 comments

With v2 you'd use volumes_from. To be honest I don't know that there's a good alternative to this in v3 yet.

Temporarily as part of the Dockerfile I've added the line
CMD cp -af /tmp/. /var/www && supervisor

To copy over all the files on start up, it doesn't feel very "docker-y" to do that though.

Any news around this issue?. We are facing the same issue with both volumes_from & named volumes. They don't get updated at service update.

Possible solution for me is that you can bind named volume to local host folder, like you do while developing. then you point in docker-compose.yml image: imageWithUpdatedCode to new image tag with updated code and kick off docker-compose up -d. After that contents of named volume will change

link where i found answer for myself
https://github.com/moby/moby/issues/30441#issuecomment-275171986

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.

The persistence of the first volume snapshot is impressive, but not updating is a problem here too because the filesystem folder it's bound to is in another container.

Is there a way to make a named volume update the data it shares on new builds? A shared dynamic ephemeral filesystem ?

Was this page helpful?
0 / 5 - 0 ratings