-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Can't reattach volumes with new contents while service is running #2776
Comments
This is by design: https://docs.docker.com/compose/#preserve-volume-data-when-containers-are-created If we were to ignore the old volume and instead create a new one from the image then anyone storing database data in a volume would lose their data when they make any change to their database image. The only way to get the new data is to |
Ah... that's unfortunate, but I understand. My idea was I had an image build front-end dependencies and attach the volume of the compiled files to the other containers that needed them. That way, I didn't need |
You should able to do that using named volumes instead of You can have one container populate the named volume and the other services mount the named volume by name ( Compose doesn't really support the "builder" container pattern, but I've been prototyping a tool (https://github.com/dnephin/dobi) to handle some of these scenarios. Currently it only supports host volumes (which would work as well), but I should add support for named volumes as well. |
I am seeing some changes in Related, named volumes made it into |
Named volumes are in docker 1.9. They are also supported in compose 1.5.2. The difference is that in 1.5.2 the name you use in In 1.6.2 it needs to be declared in a top level It should work in both versions, but will require a small change when you upgrade to 1.6 (to define either an external named volume, or changed it to use a namespaced one). |
I am pretty sure this is related to #622, and you were asking for a use-case for it, and I think I've got one.
The issue here is that new volumes aren't being properly attached to containers if the containers were already running.
Reduced test case
Gists don't allow subdirectories, but the
--SLASH--
represents... well, a/
(a subdirectory division).https://gist.github.com/CWSpear/3bdacca128641164a836
Anyway, have the above files in this structure:
Steps to reproduce
Step 1: Run:
Step 2: Visit http://localhost:8080/ (don't forget to replace
localhost
with your Docker Machine's IP if you need to) and you should seeHello World!
Step 3: Change the contents of
data/index.html
toHello Compose!
then run:Step 4: Rebuild data:
Step 5: Start up data?
Step 6: Refresh http://localhost:8080/.
Results
Expected:
Hello Compose!
Actual:
Hello World!
Addendum
You can replace Step 5 with any of these and you get the same result:
Step 5 alt (a)
Step 5 alt (b)
Step 5 alt (c)
Step 5 alt (d)
Workaround
The following does work, but it will restart
server
, and the goal here would be to not have any down time:Step 5 alt (e)
The text was updated successfully, but these errors were encountered: