This repository provides an example of using Watchtower
to automate the process of automating containers when new base images are released, proxying requests to the Docker socket via a docker-socket-proxy
container to limit the scope of available APIs.
⚠️ Note: If the host you're running on hasSELinux
orAppArmor
, you may need to run thedocker-socket-proxy
container with the--privileged
flag.
If the container you wish to automatically update is stored in a private container registry, the following environment variables are required:
REGISTRY_USER=<username>
REGISTRY_PASS=<password or token>
# Install the virtualenv package
pip3 install virtualenv
# Create a virtual environment
virtualenv .venv
# Activate the virtual environment
source .venv
pip3 install -r requirements.txt
ansible-galaxy collection install -r ansible-requirements.yml
The repository provides an Ansible Playbook
- see autoupdates.yml
To run the playbook, issue the following command:
ansible-playbook -i localhost autoupdates.yml
The repository provides an Ansible Playbook which handles
- Setting the necessary
variables
- Pulls the required Docker
images
- Creates a dedicated Docker
network
for thesocket-proxy
andwatchtower
containers
- Starts the
socket-proxy
andwatchtower
containers
- Pulls an example Docker
image
,alpine:3.13
, and creates a newtag
of this image aslatest
- i.e.
docker image tag alpine:3.13 alpine:latest
- This is done to ensure that our local image,
alpine:latest
, has a differenthash
from the remote image (onDockerHub
), which will trigger an update
- i.e.
- Starts the example Docker
image
alpine:latest
, which will be automatically updated onceWatchtower
is triggered.
# Create environment variable files
cp socket-example.env socket.env
cp tower-example.env tower.env
# Create a Docker network
docker network create \
-d bridge \
--internal \
socket-proxy-net
# Start the docker-socket-proxy container
docker run -d \
--name socket-proxy \
-v /var/run/docker.sock:/var/run/docker.sock \
--env-file socket.env \
--network socket-proxy-net \
ghcr.io/tecnativa/docker-socket-proxy:0.1.1
# Start the watchtower container
docker run -d \
--name watchtower \
--env-file tower.env \
--network socket-proxy-net \
--link socket-proxy \
ghcr.io/containrrr/watchtower:1.5.1
# Pull the alpine:3.13 image (or any image, really)
docker pull alpine:3.13
docker image tag alpine:3.13 alpine:latest
# Start the example container to automatically update
docker run -d \
--name api \
--restart unless-stopped \
--label com.centurylinklabs.watchtower.enable=true \
alpine:latest /bin/sh -c 'while true; do sleep 1; done'
# Watch the logs of `watchtower`
docker logs -f watchtower