Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if docker pull actually pulled something

Tags:

bash

docker

I've the following script to update my Nextcloud:

#!/bin/bash

set -ex

docker pull nextcloud
docker rm -f nextcloud
docker run -d -p 8080:80 -v nextcloud:/var/www/html --name nextcloud --restart=unless-stopped nextcloud
docker image prune -f

The problem is, that it creates new container even when there was noting new to pull.

How can I check, if the docker pull actually pulled something, or if my image is already up-to-date? The exit code of docker pull is 0 in both situations.

like image 615
Pitel Avatar asked Aug 01 '18 07:08

Pitel


People also ask

How do I view pulled images on docker?

The easiest way to list Docker images is to use the “docker images” with no arguments. When using this command, you will be presented with the complete list of Docker images on your system. Alternatively, you can use the “docker image” command with the “ls” argument.

What happens when you pull docker image?

Docker enables you to pull an image by its digest. When pulling an image by digest, you specify exactly which version of an image to pull. Doing so, allows you to “pin” an image to that version, and guarantee that the image you're using is always the same.

Does docker pull run the image?

docker run runs a container/command. docker pull pulls a docker image (or repository) from the docker registry.

Where does docker put pulled images?

The docker images, they are stored inside the docker directory: /var/lib/docker/ images are stored there.


1 Answers

You can check output of docker pull command:

#!/bin/bash    
set -ex

out=$(docker pull nextcloud)

if [[ $out != *"up to date"* ]]; then
   docker stop nextcloud
   docker rm -f nextcloud
   docker run -d -p 8080:80 -v nextcloud:/var/www/html --name nextcloud -- 
   restart=unless-stopped nextcloud
   docker image prune -f
fi
like image 143
anubhava Avatar answered Oct 12 '22 23:10

anubhava