Docker Community Forums

Share and learn in the Docker community.

Update volume files with new version of application's sources


(Iradorn) #1


I have a few quick questions about updating a container.
I will explain the situation:

  • I created a custom image from the Prestashop image, but it the same logic with all images
  • I need to use volumes for some folders (modules, override, etc …)

My PHP sources specific to my project, are injected into the image, and some into folders that are volumes.
I take an example:
I have a v1 images with sources in:

  • /var/www/html/modules/
  • /var/www/html/overrides/

I have volumes of those same records.
I rebuilt an image v2 with new sources in these folders.

What is the best solution to update our container ? (with new PHP sources in volumes).

thank you,

(Siju Oommen George) #2


Volumes can be shared by multiple containers.
So when you bring v2 up you can have the same volumes that v1 has.
Once v2 is up, stop v1 and redirect the requests to v2

Hope this helps :slight_smile:


(Iradorn) #3

Thank you for your answer, but the proposed solution does not quite answer my request.
Indeed, I need to update the new sources contained in the V2 image, inside the volumes.

After severals tests, I finally found my solution, don’t hesitate to tell me if it “bad practice”.
In my dockerfile, I simply:

  • copied my own sources into a temporary folder: /tmp/mysources
  • override the default CMD command with my own shell: CMD ["/bin/bash "," /tmp/ "]
  • and finally, in the shell, I copy my new sources from the tmp folder to the volumes

I hope this post will help others peoples.

(David Maze) #4

Yes, your actual application code and resources shouldn’t be in volumes. (It leads to exactly the trouble you’re running into now.)

You can do this without tweaking your image:

docker run -v $PWD:/x myimage /x/

I’d worry about the maintainability of having to do this manual step on every code/asset update, though.

(Iradorn) #5

I need to use volumes because i share data bewteen containers (ftp for instance) and i need to persist datas (customers’s upload).
But all my volumes are named volumes.
I use docker-compose for compose all my container.

(David Maze) #6

Those two things aren’t incompatible. It makes sense to use volumes for persistent data, but not for the application code that needs to be updated when the container is redeployed. A rough sketch of a Dockerfile:

COPY . /usr/src/app
WORKDIR /usr/src/app
RUN pip install .
RUN mkdir /data
VOLUME /data
CMD ./ --data-dir /data

So your application code is in (say) /usr/src/app, and the persistent data is in /data. You might need to tell the application that it’s somewhere else. There could still be data-ish content in (say) /usr/src/app/assets that gets served by the application.