-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
"docker-compose up" not rebuilding container that has an underlying updated image #4337
Comments
docker-compose up
not rebuilding container that has an underlying updated image
Thank you for the detailed reproduction steps. I'll look into this further soon, but I just wanted to note that a simpler workaround would be to run |
I'm seeing this issue too. I'm wondering if there is another workaround. |
I am having a similar issue where I'm adding new dependencies to my node application during development which cause a change to Using |
I started working on this issue and was able to reproduce the bug. I have a fix, but I'm not sure if it's in the desired direction. This issue seemed to be caused by My question: Is there a way to actually verify the age of a volume given a @shin-, let me know if you have any input. |
I have the same problem. Do you have any plan on when a fix will be released? |
+1 from me. @Dahca could you provide how to hack-fix with |
I think that this should be a high priority issue. For me the only thing that worked was to manually delete all docker images and containers and then rebuild everything again. This is of course not a practical work flow which more or less makes docker-compose useless with node projects. |
I have the same issue.
It work? |
Hi everyone, I've spent some time looking more closely at this issue today. The behavior I observed is the expected one: anonymous volumes are preserved when containers are recreated, which is a documented feature. There are a few considerations:
If you're able to share use-cases, that would be super helpful to me to figure out where the friction is regarding this issue. Thanks! |
@shin- It's been a while since I posted this issue, but from what i recall, it doesn't seem like what is happening is the same as the documented feature you are describing. If anonymous volumes are preserved when containers are recreated, then would that not be the case whether or not one uses the Is the use case repo I posted originally not suitable to help? |
@twelve17 The repo you posted helped me reproduce the problem (thanks!). What I'm interested in now is why you felt like you needed to do what you did (create an anonymous volume for Hope that makes sense! |
@shin- Ah, thanks for the clarification. The technique I did was based on this post. See "Installing Dependencies" and "The node_modules Volume Trick" sections), which explains the reasoning. Hope that helps! |
@twelve17 Thanks for the link! I see, so it's a bit of a hack to exclude a specific subfolder from a host bind. Maybe that's something we could add as part of the configuration, e.g. volumes:
- type: bind
source: .
target: /app
excludes:
- /app/node_modules and implement these exclusions as disposable anonymous volumes. Would that make sense? |
Hey folks, I have an update about this issue after talking with some of the Docker engine maintainers. It turns out having nested volumes like in this case is a really bad idea and relies mostly on having a race condition work in your favor. As a result, the idea I mentioned above isn't in consideration anymore (even if it seems to work consistently now, there's no guarantee it will going forward, so codifying it at the Compose level would be a terrible idea). That said a CLI flag to opt out of preserving anonymous volumes (as mentioned in #5400) is something we can consider, and would cover a wider range of uses. |
As a follow-up to #4337 (comment), I just submitted #5596 . Let me know if that helps! |
I also followed http://jdlm.info/articles/2016/03/06/lessons-building-node-app-docker.html and faced with the problem that anonymous volume is reused and npm dependency is not updated. But it's really easy to solve this without any PRs and other hacky solutions. Using solution from the PR you need not forget every time to specify flag So instead of this: services:
web-client:
build:
context: .
command: ["npm", "start"]
ports:
- 8080:8080
volumes:
- .:/root/app
- /root/app/node_modules use services:
web-client:
build:
context: .
command: ["npm", "start"]
ports:
- 8080:8080
volumes: # just specify what you need in container
- ./config:/root/app/config
- ./src:/root/app/src
- ./package.json:/root/app/package.json
- ./webpack.config.js:/root/app/webpack.config.js |
There's also a "good feeling" solution on SO that I found and just implemented and is working well so far: https://stackoverflow.com/a/35317425/1427426 Your build process can create a separate directory in the image to contain the
Then, in your
|
@newhouse Your solution will work but it's related to nodejs projects only. So if you have some client JS application with module bundler (for example, webpack), you need to set your |
@Jokero Yes, this definitely is a NodeJS solution with no consideration for how it might work/help/not-work with webpack. |
- Add react-bootstrap and react-router-bootstrap modules - Create NavBar.test.js with initial NavBar tests - Create NavBar.js component - Update App component to add NavBar - Update index.html with bootstrap version for react-bootstrap - Update UsersList component with bootstrap v3 classname - NOTE. docker-compose-dev.yml has been updated - WHY? When adding npm dependencies to react app, the container node_modules directory is not updated. - SOLUTION: mount the node_modules directory to volume - (docker/compose#4337 (comment))
I am also having the same problem with docker-compose version 1.17.1 |
Curious as to why this is closed, I'm still experiencing the issue on 1.22. |
@scottwilson312 #4337 (comment) Use the |
@shin- thank you, much appreciated |
I managed to get around this by adding And i don't have to use ...
"scripts": {
"start": "npm install && pm2-runtime index.js --name appone"
}
... In Dockerfile CMD ["npm", "start"] .... And i automate this with bash script to avoid tangling images or unnecessary volumes #!/bin/sh
docker-compose down &&
docker-compose rm &&
docker-compose build &&
docker-compose up -d
sleep 1
docker rmi $(docker images -f "dangling=true" -q)
echo y | docker volume prune
printf "\n... HAPPY CODING ...\n\e[0m" |
This worked for me. Thanks mate |
It seems |
This one is a bit lengthy to explain, so I have created a test project to reproduce this behavior with.
As I understand it from the
docker compose
up
documentation, the container should be rebuilt if an image was changed. However, it seems here thatdocker-compose up
is not noticing that a particular image changed, and thus is re-using an existing container which has pointers to an older image. At least that is the closest I can get to a theory. More information below the version and info.docker version:
docker info:
I am including the contents of the
README.md
here to help explain the problem in detail.Use Case
Dockerfile
./
) that prints the version of the local npm dependency from itspackage.json
. This is used to verify the results of the test case procedure.node_modules
from the container on top of the first volume. This allows changing of sources on the host machine while at the same time using the node_modules that were built for the container's platform.Steps to Reproduce
docker rm
anddocker rmi
.test2_run1
tag. This state represents the project using version 1.0.0 of the local NPM dependency.docker-compose build
. All steps should run without any cache usage if step 2 was followed correctly. Note the version of the local NPM dependency during thenpm install
command, e.g.+-- [email protected]
.docker-compose up
. Browse tohttp://localhost:8000
. The page should report version1.0.0
.up
command was issued.)test2_run2
tag. This introduces a small change to the NPM'sindex.js
file, and a version bump in itspackage.json
to1.0.1
.docker-compose build
. Only the instructions up toCOPY ./my-npm ...
should use a cache. (E.g., the docker output prints---> Using cache
for that instruction.) All subsequent steps should be run by docker. This is because the changes introduced in step 7 to the NPM package should have invalidated the cache for theCOPY ./my-npm ...
command, and, as a result, subsequent steps too. Confirm that during thenpm install
command, the new version of the NPM is printed in the summary tree output, e.g.+-- [email protected]
.docker-compose up
. Browse tohttp://localhost:8000
. The page should report version1.0.1
.Expected behavior: Page in step 9 should report
1.0.1
. That is, a change in the local npm should be reflected in the container viadocker-compose up
.Actual behavior: Page in step 9 reports
1.0.0
.Note that docker itself is re-building images as expected. The observed issue is not that docker is re-using a cached image, as the output shows it re-running NPM install and showing the new version of the local NPM dependency. The issue is that
docker-compose
is not seeing that the underlying images that comprise thedctest_service1
container have been updated.In fact, running bash in the container allows us to see that the container has the updated
my-npm
module files, but thenode_modules
version is stale:Workaround: Use
docker rm
to remove thedctest_service1
container. Then re-rundocker-compose up
, which will re-create the container using the existing images. Notable in this step is that no underlying images are re-built. In re-creating the container,docker-compose
seems to figure out to use the newer volume that has the updatednode_modules
.See the
output
directory for the output printed during the first run (steps 4 and 5) and the second run (steps 8 and 9).The text was updated successfully, but these errors were encountered: