Let's say we have a dockerfile which contains a base image directive pointing to BaseImage:
FROM BaseImage
...
Is there any way so we can detect if BaseImage has been modified since the last build, so we can avoid building the image again?
Let's say we have a dockerfile which contains a base image directive pointing to BaseImage:
FROM BaseImage
...
Is there any way so we can detect if BaseImage has been modified since the last build, so we can avoid building the image again?
There was a previous question similar to this asking "How to automatically update your docker containers, if base-images are updated".
There is no standard way, but the user who answered (bsuttor) submitted the script he uses to check for updates to the base image in the Docker repo:
We use a script which checks if a running container is started with the latest image. We also use upstart init scripts for starting the docker image.
#!/usr/bin/env bash
set -e
BASE_IMAGE="registry"
REGISTRY="registry.hub.docker.com"
IMAGE="$REGISTRY/$BASE_IMAGE"
CID=$(docker ps | grep $IMAGE | awk '{print $1}')
docker pull $IMAGE
for im in $CID
do
LATEST=`docker inspect --format "{{.Id}}" $IMAGE`
RUNNING=`docker inspect --format "{{.Image}}" $im`
NAME=`docker inspect --format '{{.Name}}' $im | sed "s/\///g"`
echo "Latest:" $LATEST
echo "Running:" $RUNNING
if [ "$RUNNING" != "$LATEST" ];then
echo "upgrading $NAME"
stop docker-$NAME
docker rm -f $NAME
start docker-$NAME
else
echo "$NAME up to date"
fi
done
And init looks like
docker run -t -i --name $NAME $im /bin/bash