Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make docker-compose pull new images?

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?

like image 990
Ron Avatar asked Nov 27 '18 10:11

Ron


3 Answers

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

like image 196
Kristian Glass Avatar answered Nov 15 '22 04:11

Kristian Glass


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
like image 5
David Maze Avatar answered Nov 15 '22 03:11

David Maze


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.

like image 3
Justin Ludwig Avatar answered Nov 15 '22 05:11

Justin Ludwig