Docker Container auto update

Docker Linux

To keep docker containers up to date without your interaction you have many ways.
One of them is to use crontab to pull newest docker images and apply them to your containers.

I have set up scheduled update using "crontab -e" to run twice a month, you can choose different schedule.

# m h  dom mon dow   command
5 2 1,15 * * /path/to/script/container-update.sh

#!/bin/bash
echo Pulling newest images for all running containers:
docker images | grep -v REPOSITORY | awk '{print $1}' | xargs -L1 docker pull

sleep 4; docker restart $(docker ps -q)

echo Done. Removing unused Images...
docker image prune -a --force

If you have any custom containers what are not getting any updates you can always update at least the packages within.

#!/bin/bash
# Define the conainer_names  variable with a list of docker containers you want update
conainer_names=("containerFox" "containerSun" "containerblob")

# Run update for all the defined containers
for dns_name in "${conainer_names[@]}"
do
    # Set Timezone in case it is asking to reconfigure it after the container reboot
    docker exec -it "$conainer_names" bash -c 'echo -e "Europe\nLondon" | dpkg-reconfigure tzdata -f teletype'
    # Run apt update or you can use other commands here if it is not debian based container.
    docker exec -it "$conainer_names" bash -c 'apt update && apt upgrade -y && apt autoremove -y'
done