Robba
Robba

Reputation: 8324

Can I make Docker do always a pull when performing a run?

We regularly push new versions of our containers to our private Docker registry. We also have a set of containers we start when we need them like so:

docker run -e "env=val" -p 9001:80 --name blah --rm our_repo/the_image:latest

The thing we run into is when we push a new version of the_image:latest to our registry, our machines will already have a the_image:latest cached locally and it seems that the run command does not perform a pull of the image.

Is there a way to make it do that other than always having to manually issue a docker pull our_repo/the_image:latest command?

Thanks in advance

Upvotes: 36

Views: 27567

Answers (2)

Adiii
Adiii

Reputation: 59916

As mentioned by @Linpy you can try the nightly builds, but if you do not want to update you can try the below command. It will pull the image on every run.

docker run -it $(docker pull alpine | grep Status |  awk 'NF>1{print $NF}')

Or

docker run -e "env=val" -p 9001:80 --name blah --rm $(docker pull our_repo/the_image:latest | grep Status |  awk 'NF>1{print $NF}')

You can also use AWK with out grep

docker run -it $(docker pull alpine |  awk 'END{print}' | awk 'NF>1{print $NF}')

Bash Script

#!/bin/bash
image_name="${1}"
docker run -it $(docker pull $image_name |  awk 'END{print}' | awk 'NF>1{print $NF}')

$ ./test.sh alpine

Upvotes: 2

LinPy
LinPy

Reputation: 18578

docker run --pull=always

is merged here github

will ship as part of Docker 19.09 but you can download nightly builds with that change

commit

Upvotes: 75

Related Questions