Build from dockerfile does not recreate image after changes in dockerfile or its context.
⚠️ Please verify that this bug has NOT been reported before.
- [X] I checked and didn't find similar issue
🛡️ Security Policy
- [X] I agree to have read this project Security Policy
Description
Images are not rebuilt upon deploy or update, if dockerfile was changed. However, I am not sure if this problem could be simply fixed without causing a negative effect on stacks without dockerfiles. In this case a button forcing --build is good enough solution
👟 Reproduction steps
Let's assume having such compose file:
services:
my-dockerfile:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
Docker file itself can be empty like:
FROM alpine:latest
- Deploy service
- change docker file
- deploy service
👀 Expected behavior
The image should rebuilt like using docker-compose up --build -d
😓 Actual Behavior
Only container recreated like using docker-compose up -d (without --build)
Dockge Version
1.4.2
💻 Operating System and Arch
Debian
🌐 Browser
Chrome
🐋 Docker Version
Docker version 20.10.24+dfsg1, build 297e128
🟩 NodeJS Version
No response
📝 Relevant log output
No response
Would also vote for an extra button called "build" on the side of the "update" one ;-)
I am using dockerfile_inline and have the same problem (surprise :-)).
If there is no image configured, but a build section, update button could automatically build.
No need for an extra button, especially because update does nothing.
deploy should always build in this case.
On my side it's also related to watchtower. As far as I read, watchtower uses the base image and does not see the changes in the compose file. This seems to be ok, because I deploy anyways, if I change the compose file. But if watchtower only downloads the image without applying the dockerfile, this would strip the additional parts from the image and I would need another solution instead of watchtower. If at some point dockge already does all the basic work, it would be the ideal place to add some scheduling to do regular updates.
My 2 cents on the fact that the update button should also force build image if their were modifications within the build context is that maybe it will not be the behaviour expected but apart from that it seems perfectly OK IMO.
Adding some additional information. If you want update button to automatically re build the image. You can use pull_policy: build
Reference docker compose documentation
Not saying this solves the original ask of potential checking if the dockerfile was modified and forced the rebuild VS doing a rebuild every single time.
Sample:
services:
my-dockerfile:
build:
context: .
dockerfile: Dockerfile
pull_policy: build
restart: unless-stopped
thanks for the pointer, I didn't look into pull_policy because I didn't want to pull it :-)
this actually works for me (only the build, not the final goal):
...
nodered:
container_name: nodered
#image: docker.io/nodered/node-red
pull_policy: build
build:
context: .
dockerfile_inline: |
FROM docker.io/nodered/node-red:latest
USER root
RUN apk add --no-cache chromium
USER node-red
...
the build takes longer for the first time and then runs quite fast (though it's always creating a new image, at least that's what it says). If I change the dockerfile_inline value, then it takes longer again (e.g. the apk command if I add a package or if I add another RUN line).
And the inline file is shown in green, which is nice.