How to automatically update your docker containers, if base-images are updated

后端 未结 16 685
别那么骄傲
别那么骄傲 2020-12-04 04:17

Say I have a trivial container based on the ubuntu:latest. Now there is a security update and ubuntu:latest is updated in the docker repo .

16条回答
  •  攒了一身酷
    2020-12-04 05:08

    Here is a simplest way to update docker container automatically

    Put the job via $ crontab -e:

    0 * * * * sh ~/.docker/cron.sh
    

    Create dir ~/.docker with file cron.sh:

    #!/bin/sh
    if grep -Fqe "Image is up to date" << EOF
    `docker pull ubuntu:latest`
    EOF
    then
        echo "no update, just do cleaning"
        docker system prune --force
    else
        echo "newest exist, recompose!"
        cd /path/to/your/compose/file
        docker-compose down --volumes
        docker-compose up -d
    fi
    

提交回复
热议问题