The Docker community has created a number of open source tools that help us with various use cases. In this article, the author recommends 5 most useful Docker tools, including Watchtower (automatic update Docker container), Docker-GC (garbage collection of containers and images), Docker-Slim (container slim), Rocker: Breaking the limits of Dockerfile and CTOP (the container’s class-top interface).

The Docker community has created many open source tools that can help you handle more use cases than you could ever imagine.

You can find a lot of cool Docker tools online, most of which are open source and can be found on Github. For the past two years, I’ve been a big fan of Docker and have used it for most development projects. Once you start using Docker, you’ll find that it applies to more scenarios than you initially expected. You’ll want Docker to do as much for you as possible, and it won’t let you down!

The Docker community is very active and there are so many useful tools coming out every day that it’s hard to keep track of all the innovation that’s happening in the community. To help you out, I’ve collected some of the fun and useful Docker tools I use in my daily work that have increased my productivity and reduced the amount of work THAT would otherwise have to be done manually.

Here are the five tools I recommend.

Watchtower: Automatically updates Docker containers

Watchtower monitors running containers and monitors any changes to their images when they are initially started. When Watchtower detects that an image has changed, it automatically restarts the container with the new image. I wanted to try out the latest build image in my local development environment, so I used it.

Watchtower itself is packaged as a Docker image, so you can run it just like any other container. To run Watchtower, you need to execute the following command:

$ docker run -d --name watchtower --rm -v /var/run/docker.sock:/var/run/docker.sock v2tec/watchtower --interval 30
Copy the code

In the command above, we start the Watchtower container with a mount file called /var/run/docker.sock. This is necessary so that Watchtower can interact with the Docker daemon API. We pass 30 seconds to the interval option. This option defines the polling interval for Watchtower. Watchtower supports more options that you can use as described in the documentation.

We now launch a container that Watchtower can monitor.

$ docker run -p 4000:80 --name friendlyhello shekhargulati/friendlyhello:latest
Copy the code

Watchtower will now begin gently monitoring the FriendlyHello container. When I push a new image to the Docker Hub, Watchtower will detect a new available image on subsequent runs. It will gracefully stop that container and start the container with the new image. It will pass the options we passed to the run command earlier. In other words, the container will still start with the 400:80 publishing port.

By default, Watchtower will poll the Docker Hub registry for updated images. Watchtower can be configured to poll private registries by passing registry credentials in the environment variables REPO_USER and REPO_PASS.

To learn more about Watchtower, you can read the Watchtower documentation at github.com/v2tec/watch…

GitHub address: github.com/v2tec/watch…

Docker-gc: Garbage collection of containers and images

The Docker-GC tool helps you clean up Docker hosts by removing unnecessary containers and images. It deletes all containers that have existed for more than an hour. In addition, it removes images that do not belong to any indent containers.

You can use docker-GC as a script and container. We will run docker-GC as a container. To use docker-GC to find all containers and images that can be deleted, run the following command:

$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -e
DRY RUN=1 spotify/docker-gc
Copy the code

Sock file is loaded so that docker-GC can interact with the Docker API. We passed an environment variable DRY_RUN=1 to find containers and images to be deleted. If this parameter is not provided, docker-GC removes all containers and images. It is best to confirm in advance what docker-GC will delete. The output of the above command is as follows:

[2017-04-28T06:27:24] [INFO] : The following container would have been removed 0c1b3b0972bb792bee508 60c35a4 bc08ba32b527d53eab173d12a15c28deb931/vibrant_ yonath [2017-04-28T06:27:24] [INFO] : The following container would have been removed 2a72d41e4b25e2782f7844e188643e395650a9ecca660e7a0dc2b7989e5acc28 /friendlyhello_ web [2017-04-28T06:27:24] [INFO] : The following image would have been removed sha256:00f017a8c2a6e1 fe2f fd05c281 f27d069d2a99323a8cd514dd35f228ba26d2ff [busybox: latest] [2017-04-28T06:27:24] [ INFO] : The following image would have been removed sha256 :4a323b466a5ac4ce6524 8dd970b538922c54e535700cafe9448b52a3094483ea [hello-world:latest] [2017-04-28T06:27:24] [INFO] : The following image would have been removed sha256:4a323b4 66a5ac4ce65248dd970b538922c54e535700cafe9448b52a3094483ea 2.7 slim] [python:Copy the code

If you agree with the Docker-GC cleanup scheme, you can run the docker-GC cleanup again without DRY_RUN.

$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock spotify/docker-gc
Copy the code

Docker-gc also supports a few other options. You are advised to read the Docker-GC documentation for more information: github.com/spotify/doc…

GitHub address: github.com/spotify/doc…

Docker-slim: The miracle weight-loss drug for the container

If you’re worried about the size of your Docker image, the Docker-Slim can help.

The Docker-Slim tool uses static and dynamic analysis to slim down your bloated images. To use Docker-Slim, download the binary installation package for Linux or Mac from Github. Once it’s downloaded successfully, add it to your system variable PATH.

For example, I created a Docker image named FriendlyHello with the size of 194MB (as shown below) by referring to the official Docker document:

As you can see, for a simple application, we had to download 194 MB of data. Let’s use the Docker-Slim to see how much fat it can cut.

$ docker-slim build --http-probe friendlyhello
Copy the code

The Docker-Slim tool performs a series of checks and measures on the fat image to create a thin version of the image. Let’s take a look at the size of this weight loss.

As you can see, the mirror size has been reduced to 24.9 MB. You can start the container and it will behave the same way. The Docker-Slim tool supports Java, Python, Ruby, and Node.js applications.

Try it yourself and see how much you can lose. In my personal projects, I’ve found that it works in most situations. You can learn more about docker-Slim from its documentation: github.com/docker-slim…

GitHub address: github.com/docker-slim…

Rocker: Breaking the limit of Dockerfile

Most developers using Docker use Dockerfile to build images. Dockerfile is a declarative method for defining all commands that a user can invoke on the command line to assemble an image.

Rocker (github.com/grammarly/r…). Added new instructions to the Dockerfile instruction set. Grammarly created Rocker to solve their problems with the Dockerfile format.

The Grammarly team wrote an in-depth blog post explaining why they created it. I suggest you read it to better understand Rocker. In their post, they highlighted two issues:

  • Docker image size.
  • Slow build speed.

The blog also mentions some new instructions that Rocker has added. Refer to the Rocker documentation for all Rocker supported directives: github.com/grammarly/r…

  • MOUNT is used to share volumes between builds so that they can be reused by dependency management tools.
  • There is already a FROM directive in Dockerfile. Rocker allows us to add more than one FROM directive. This means you can create multiple images from a single Rockerfile. The first set of instructions is used to build all of the product’s dependencies; The second set of instructions is used to build the product; This can greatly reduce the mirror size.
  • Tags are used to identify images at different stages of construction, which means you don’t have to TAG each image manually.
  • PUSH is used to PUSH an image to the mirror repository.
  • ATTACH lets you run the intermediate steps interactively. This is very useful for debugging.

To use Rocker, you must first install it on your machine. For Mac users, this is as simple as running a few brew commands:

$ brew tap grammarly/tap
$ brew install grammarly/tap/rocker
Copy the code

Once installed, you can use Rocker to build the image by passing in Rockerfile:

FROM python:2.7-slim WORKDIR /app ADD. /app RUN PIP install -r requiretions. TXT EXPOSE 80 ENV NAME World CMD ["python","app.Py"] TAG shekhargulati/ friendlyhello:{{ .VERSION }} PUSH shekhargulati/friendlyhello:{{ .VERSION }}Copy the code

To build an image and push it to the Docker Hub, you can run the following command:

$rocker d build -- push-var version-1.0Copy the code

GitHub address: github.com/grammarly/r…

Ctop: The top-level interface of a container

Ctop is a tool I recently started using that provides a real-time metric view of multiple containers. If you are a Mac user, you can use brew installation as follows:

$brew install cTOP Once the installation is complete, you can start using CTOP. For now, you just need to configure the DOCKER_HOST environment variable.

You can run the ctop command to see the status of all containers.

To view only the running container, use the ctop -a command.

Ctop is a simple tool that is useful for understanding the containers running on your host. You can learn more about this in the CTOP documentation: github.com/bcicen/ctop…

GitHub address: github.com/bcicen/ctop

These are the 5 Docker tools I found useful. Do you use Docker tools in your daily work? I hope you find these tools helpful, and feel free to suggest any you find useful in the comments.