How to make docker-compose pull new images?
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
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