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.
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.
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.
docker run runs a container/command. docker pull pulls a docker image (or repository) from the docker registry.
The docker images, they are stored inside the docker directory: /var/lib/docker/ images are stored there.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With