By Retler
Hello,
We have a 2-stage Dockerfile (Build+run) where we use a build ARG in the 1st stage. This build ARG is injected during the docker build ... command. When rebuilding the image with the same name and tag, but changing the build arg to something else, the value of the build ARG changes locally (can be verified by starting up the image locally), but when pushed to the DO container registry, the image still contains the old build ARG.
Is this a known issue? Is there anything in the caching mechanism than skips invalidation on ARG variables in the Dockerfile?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I have managed to make a more simple and minimal Dockerfile which you can use to recreate the bug:
FROM alpine:latest
ARG PASSWORD
RUN echo $PASSWORD > /password
ENTRYPOINT ["cat", "/password"]
Steps to recreate the cache bug:
Build this Dockerfile with docker build -t registry.digitalocean.com/myreg/failcache -f failcache.dockerfile --build-arg PASSWORD=test .
Push the image to DO container registry: docker push registry.digitalocean.com/myreg/failcache
Run the container somewhere. In particular you can use kubernetes with the following pod spec:
apiVersion: v1
kind: Pod
metadata:
labels:
app: failcache
name: failcache
namespace: keycloak
spec:
serviceAccount: <sa-with-pull-access-to-registry>
containers:
- image: registry.digitalocean.com/myreg
imagePullPolicy: Always
name: failcache
Notice how the log of the container says “test”
Now rebuild the image locally with docker build -t registry.digitalocean.com/myreg/failcache -f failcache.dockerfile --build-arg PASSWORD=another-test .
Push the image again to DO container registry and recreate the pod from step 3. The container log will still say “test”, even though the build-arg has changed.
Any insights on this is highly appreciated!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.