Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the useful open source Docker tools

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the good open source Docker tools". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "what are the good open source Docker tools" together!

Watchtower: Automatically update Docker containers

Watchtower monitors running containers and monitors for changes in the mirrors of these containers 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 the latest build mirror 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

In the above command, we started the Watchtower container with a mount file/var/run/docker.sock. This is necessary to enable Watchtower to interact with Docker daemon APIs. We pass 30 seconds to the interval option interval. 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

Watchtower will now begin gently monitoring the friendlyhello container. When I push a new image to Docker Hub, Watchtower will detect a new available image in the next run. It will gracefully stop that container and start it with the new image. It will pass the options we passed to the run command earlier. In other words, the container will still start using the 4000:80 publishing port.

By default, Watchtower polls 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, we recommend reading the Watchtower documentation.

https://github.com/v2tec/watchtower/blob/master/README.md GitHub Address: https://github.com/v2tec/watchtower

Docker-GC: Garbage collection of containers and mirrors

Docker-gc helps you clean up Docker hosts by removing unwanted containers and images. It deletes all containers that are older than an hour. In addition, it removes mirrors that do not belong to any indwelling 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 mirrors that can be deleted, the command is as follows:

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

In the above command, we load the docker.sock file so docker-gc can interact with Docker API. We pass an environment variable DRY_RUN=1 to find containers and mirrors to be deleted. If this parameter is not provided, docker-gc deletes all containers and mirrors. It is best to confirm in advance what docker-gc is deleting. 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 [python:2.7-slim]

If you agree with the docker-gc cleanup scheme, you can run docker-gc again without DRY_RUN to perform the cleanup.

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

Docker-gc also supports a number of other options. I suggest you read the docker-gc documentation for more information:

https://github.com/spotify/docker-gc/blob/master/README.md GitHub Address: https://github.com/spotify/docker-gc

Docker-slim: The magic diet pill for containers

If you're worried about the size of your Docker image, docker-slim can help you out.

Docker-slim tools use static and dynamic analysis methods to slim down your bloated mirror. To use docker-slim, you can download binary packages for Linux or Mac from Github. After a successful download, add it to your PATH system variable.

For example, I created a Docker image named friendlyhello, which is 194MB in size (see below), referring to the official Docker documentation:

As you can see, for a simple application, we have to download 194 MB of data. Let's use docker-slim to see how much fat it can shed.

$ docker-slim build --http-probe friendlyhello

The docker-slim tool performs a series of checks and measurements on the fat mirror to create a thin version. Let's look at this slimmed-down size.

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

Try it yourself and see how much you can reduce. In my personal projects, I have found that it works in most cases. You can learn more about docker-slim from its documentation:

https://github.com/docker-slim/docker-slim/blob/master/README.md GitHub Address: https://github.com/docker-slim/docker-slim

Rocker: Breaking the limits of Dockerfile

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

Rocker (https://github.com/grammarly/rocker) adds new instructions to the Dockerfile instruction set. Grammarly created Rocker to solve the Dockerfile format problem they encountered. The Grammarly team wrote an in-depth blog explaining why they created it. I suggest you read it to get a better understanding of Rocker. They highlighted two issues in their blog post:

Docker image size.

Slow build speed.

The blog also mentions some of the new instructions Rocker has added. Refer to the Rocker documentation for all commands Rocker supports:

https://github.com/grammarly/rocker/blob/master/README.md

MOUNT is used to share volumes between builds so that they can be reused by dependency management tools.

There is already a FROM command in Dockerfile. Rocker allows us to add more than one FROM instruction. This means that you can create multiple mirrors from a single Rockerfile. The first batch of instructions is used to build all dependencies of the product; the second batch of instructions is used to build the product; this can greatly reduce the image size.

TAG is used to identify mirrors at different stages of construction, which means you don't have to tag each mirror manually.

PUSH is used to push mirrors to the mirror repository.

ATTACH enables you to run intermediate steps interactively. This is useful for debugging.

To use Rocker, you must first install it on your machine. For Mac users, it's simply running a few brew commands:

$ brew tap grammarly/tap $ brew install grammarly/tap/rocker

Once the installation is complete, you can build the image using Rocker by passing Rockerfile:

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 }}

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

$ rocker d build --push -var VERSION-1.0 GitHub: github.com/grammarly/rocker

5. ctop: the top-level interface of the container

Ctop is a tool I recently started using that provides real-time metrics views of multiple containers. If you are a Mac user, you can install it using brew as follows:

$ brew install ctop

Once installed, you can start using ctop. For now, you just need to configure the DOCKER_HOST environment variable.

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

If you want to see only the running container, you can use ctop -a.

Ctop is a simple tool that is helpful in understanding the containers running on your host. You can read more about this in the ctop documentation:

https://github.com/bcicen/ctop/blob/master/README.md GitHub address: https://github.com/bcicen/ctop Thank you for reading, the above is "what are the good open source Docker tools" content, after the study of this article, I believe that everyone has a deeper understanding of what are the good open source Docker tools, and the specific use needs to be verified by everyone. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report