Docker
Jump to navigation
Jump to search
Copy files to/from container
$ docker cp myfile.txt container_name:/srv/www/folder/
List images
$ docker images
Tag an image
$ docker tag 7d9495d03763 maryatdocker/docker-whale:latest
Log-in for push/pull operations
$ docker login --username=username --email=[email protected]
Push image
$ docker push maryatdocker/docker-whale
Remove an image
$ docker rmi -f imageid
Run a script whenever a container gets updated (or rebuilt) using Watchtower
Assuming the image is test/mhan, and the container is called mhan.
1. Install Watchtower
docker run -d \
--name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower --cleanup --schedule "0 3 * * *"
2. Create a notification script that Watchtower will call after every successful update
# File: /srv/updates/watchtower-mhan-notification.sh
#!/bin/bash
if [[ "$WATCHTOWER_NOTIFICATION_REPORT" == *"test/mhan"* ]]; then
echo "$(date) - mhan image was updated → running script" >> /srv/updates/mhan/update.log
/srv/updates/mhan/update.sh
fi
3. Make the script executable
chmod +x /srv/updates/watchtower-mhan-notification.sh
4. Restart Watchtower with the notification hook
docker rm -f watchtower
docker run -d \
--name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /srv/updates/watchtower-mhan-notification.sh:/watchtower-mhan-notification.sh \
-e WATCHTOWER_NOTIFICATIONS=exec \
-e WATCHTOWER_NOTIFICATION_EXEC_CMD=/watchtower-mhan-notification.sh \
-e WATCHTOWER_CLEANUP=true \
containrrr/watchtower --schedule "0 4 * * *"