5 Essential Docker Utilities to Boost Your Container Workflow
Discover five powerful Docker utilities—Watchtower, docker‑gc, docker‑slim, Rocker, and ctop—that automate container updates, clean up unused images, shrink image sizes, enhance Dockerfile capabilities, and provide real‑time container monitoring, each with installation steps, usage examples, and links to their documentation.
The Docker community has created many open‑source tools that can handle use cases beyond what you might imagine.
You can find many cool Docker tools online, most of which are open source and available on GitHub. Over the past two years I have been enthusiastic about Docker and used it in most development projects. Once you start using Docker, you realize its applicable scenarios are far more than you initially expected, and you will wish Docker could do even more for you, which it often does.
The Docker community is very active, with new useful tools appearing daily, making it hard to keep up with all innovations. To help, I have collected several interesting and practical Docker tools that improve work efficiency and reduce manual effort.
1. Watchtower: Automatic Docker Container Updates
Watchtower monitors running containers and checks whether the image they were started from has changed. When a new image is detected, Watchtower automatically restarts the corresponding container with the updated image.
Watchtower itself is packaged as a Docker image, so you can run it like any other container. To run Watchtower:
$ docker run -d --name watchtower --rm -v /var/run/docker.sock:/var/run/docker.sock v2tec/watchtower --interval 30This command mounts /var/run/docker.sock so Watchtower can interact with the Docker daemon API and sets the polling interval to 30 seconds.
Example of a container that Watchtower can monitor:
$ docker run -p 4000:80 --name friendlyhello shekhargulati/friendlyhello:latestWhen a new image is pushed to Docker Hub, Watchtower detects it, gracefully stops the old container, and restarts it with the new image while preserving the original port mapping.
By default Watchtower polls Docker Hub for updates; you can configure it to poll private registries by providing REPO_USER and REPO_PASS environment variables.
More information: Watchtower README
2. docker‑gc: Garbage Collection for Containers and Images
docker‑gc removes unnecessary containers and images from a Docker host. It deletes containers older than one hour and any images not referenced by a remaining container.
Run docker‑gc as a container:
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -e DRY_RUN=1 spotify/docker-gcThe DRY_RUN=1 flag shows what would be removed without actually deleting anything. Removing the flag performs the cleanup.
Example output (dry run):
[2017-04-28T06:27:24] [INFO] : The following container would have been removed 0c1b3b0972bb...To perform the actual cleanup, omit DRY_RUN:
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock spotify/docker-gcMore details: docker‑gc README
3. docker‑slim: Shrink Your Docker Images
If you are concerned about image size, docker‑slim can dramatically reduce it.
docker‑slim uses static and dynamic analysis to create a slimmer version of a bulky image. After downloading the binary for Linux or macOS and adding it to your PATH, you can run: $ docker-slim build --http-probe friendlyhello For the example friendlyhello image (originally 194 MB), docker‑slim reduces the size to about 24.9 MB while preserving functionality. It supports Java, Python, Ruby, and Node.js applications.
More information: docker‑slim README
4. Rocker: Extending Dockerfile Capabilities
Most Docker users build images with a Dockerfile. Rocker adds new directives to the Dockerfile syntax, addressing two common problems: large image size and slow build speed.
Key Rocker directives include:
MOUNT : Share a volume between builds for dependency caching.
FROM (multiple): Create multiple images in a single Rockerfile.
TAG : Tag images at different build stages automatically.
PUSH : Push images to a registry.
ATTACH : Run intermediate steps interactively for debugging.
Install Rocker on macOS with Homebrew:
$ brew tap grammarly/tap</code>
<code>$ brew install grammarly/tap/rockerExample Rockerfile snippet:
FROM python:2.7-slim
WORKDIR /app
ADD . /app
RUN pip install -r requirements.txt
EXPOSE 80
ENV NAME World
CMD ["python","app.py"]
TAG shekhargulati/friendlyhello:{{ .VERSION }}
PUSH shekhargulati/friendlyhello:{{ .VERSION }}Build and push the image: $ rocker d build --push -var VERSION=1.0 More details: Rocker README
5. ctop: Top‑Like Interface for Containers
ctop provides a real‑time, top‑style view of multiple containers. Install it on macOS via Homebrew: $ brew install ctop After installation, configure the DOCKER_HOST environment variable and run ctop to see container status, or ctop -a to view only running containers.
More information: ctop README
These five Docker tools—Watchtower, docker‑gc, docker‑slim, Rocker, and ctop—can help you automate updates, clean up unused resources, shrink image sizes, enhance Dockerfile functionality, and monitor containers efficiently.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
