I am using the latest
tag in my Dockerfile
in the FROM
statement:
# Dockerfile
FROM registry.website.com/base-image:latest
Every time my latest
version changes I need to re-pull that image.
Unfortunately, docker just takes the cached version.
I tried
docker-compose build --no-cache
and
docker-compose up --build --force-recreate project
But it always looks like this:
> docker-compose up --build --force-recreate project
Building project
Step 1/12 : FROM registry.website.com/base-image:latest
---> e2a0bcaf3dd7
Any ideas why it's not working?
I think you're looking for docker-compose pull
:
$ docker-compose help pull
Pulls images for services defined in a Compose file, but does not start the containers.
So docker-compose pull && docker-compose up
should do what you want, without needing to constantly wipe your cache or hard-code container names outside of your compose file
This is the default behavior of docker run
and similar commands: it will pull an image if you don't already have it, but if you do, it assumes the one you already have is correct. In this case since the image isn't directly listed in the docker-compose.yml
file you don't have a lot of shortcuts; you could script something like
sed -ne 's@^FROM \(.*/.*\)@\1@p' | xargs docker pull
to pull everything listed in a FROM
line, but not base images for multi-stage builds (image names must contain a slash); that's possibly overkill.
I've seen several suggestions to avoid using latest
tags; this is one of a couple of big reasons (you also don't control the major version of prepackaged software, and won't get consistent deployments on multi-host setups). If you have a continuous-integration setup building your frequently-changing image, you might consider tagging it with a date stamp or build ID and putting that in the FROM
line. You can use an ARG
to make this more configurable, and pass that through from docker-compose.yml
, ultimately coming back to an environment variable.
I'd guess you'll probably wind up with a shell script wrapper no matter what, and if you're set on the latest
version it could just look like
#!/bin/sh
set -e
docker pull registry.website.com/base-image:latest
docker build -t ... .
docker-compose up -d
To re-pull your base images and re-build, run:
docker-compose build --pull
See What's the purpose of "docker build --pull" for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With