Reputation: 8324
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
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