Welcome!

Blog Feed Post

5 Docker Utilities You Should Know

You can find a lot of cool Docker utilities on the web. Most of these are open source and available on Github. Over the last two years, I have become quite active with Docker, using it for most of my development projects. As you start using Docker, you will find it is suitable for more use cases than you may have initially envisioned. You will want Docker to do a little more for you—and it will not disappoint!

The Docker community is very active, with a lot of useful utilities popping up daily. It is difficult to keep check of all the innovation happening in the community. To help you, I have collected some interesting and useful Docker utilities, which I use in my daily work. These utilities make me more productive, eliminating what otherwise would have been manual work.

Let’s go through each of the utilities I find useful in my journey to Dockerize stuff.

1. watchtower: Automatically update Docker containers

Watchtower monitors running containers and watches for changes to the images those containers were originally started from. When Watchtower detects that an image has changed, it automatically restarts the container using the new image. I use it in my local development where I would like to try out the latest built image.

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

Docker utilities - docker runhttps://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1456px) 100vw, 1456px" data-recalc-dims="1" />

In the command above, we started Watchtower container with a mounted file `/var/run/docker.sock`. This is required so that Watchtower can interact with Docker daemon API. We passed an option `interval` of 30 seconds. This option defines the Watchtower poll interval. Watchtower support a few more options, which you can use as described in their documentation.

Let’s now start a container that Watchtower can monitor.

Docker utilities - docker runhttps://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1470px) 100vw, 1470px" data-recalc-dims="1" />

Now, Watchtower will start monitoring `friendlyhello` container. When I push the new image to Docker Hub, Watchtower, in its next run, will detect that a new image is available. It will gracefully stop the container and start the container using the new image. It will pass the options that we passed to the run command. In other words, the container will be started with `4000:80` publish ports option.

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

To learn more about Watchtower, I recommend reviewing the Watchtower documentation.

2. docker-gc: Garbage collection of container and images

The docker-gc utility helps clean up your Docker host by removing containers and images that are not required. It removes all the containers that existed more than an hour ago. Also, it removes images that don’t belong to any remaining containers.

You can use docker-gc both as a script and container. We will run docker-gc as a container. Let’s use docker-gc to find all the containers and images that can be removed.

Docker utilities - docker runhttps://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1468px) 100vw, 1468px" data-recalc-dims="1" />

In the command shown above, we mounted Docker socket file so that docker-gc can interact with Docker API. We passed an environment variable DRY_RUN=1 to find which containers and images will be removed. If we don’t provide this option, docker-gc will remove all of them. It is good to first verify everything docker-gc will clean. The output of the above command appears below.

Docker utilities - docker runhttps://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1468px) 100vw, 1468px" data-recalc-dims="1" />

If you are fine with the docker-gc clean up plan, you can again run docker-gc without DRY_RUN flag to perform the clean up.

Docker utilities - docker runhttps://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1460px) 100vw, 1460px" data-recalc-dims="1" />

The output of the above command will tell you all the images and the containers that docker-gc removed.

There are few more options that docker-gc supports. I recommend you read the docker-gc documentation to learn more about it.

Meeting the challenges of delivering microservices applications in the enterprisehttps://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/02/Meeting-... 229w" sizes="(max-width: 195px) 100vw, 195px" data-recalc-dims="1" />WHITE PAPER

Meeting the Challenge of Delivering Microservices Applications in the Enterprise

Essential Practice for Continuous Delivery at Enterprise Scale

Learn how to address three practical challenges of using microservices architecture, including: how to handle changing deployment patterns, how to deal with dependencies between services, and how to avoid getting stuck with the wrong implementation technology.

3. docker-slim: Magic diet pill for your containers

If you are worried about the size of your Docker images, you will be blown away by docker-slim.

The docker-slim utility uses static and dynamic analysis to create skinny image variants of your fat images. To use docker-slim, you have to download its binary from Github. Binaries are available for Linux and Mac. Once you download the binary, add it to your PATH.

I created a Docker image for example application `friendlyhello` used in the Docker official documentation. The image size, as you can see below, is 194 MB.

Docker utilities - docker slimhttps://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1456px) 100vw, 1456px" data-recalc-dims="1" />

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 remove.

Docker utilities - docker slimhttps://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1464px) 100vw, 1464px" data-recalc-dims="1" />

The docker-slim utility will carry out a series of steps–inspecting fat image, instrument fat image, finally creating a slim version of the image. Let’s look at the size of the slim variant.

Docker utilities - docker slimhttps://i2.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i2.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i2.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1462px) 100vw, 1462px" data-recalc-dims="1" />

As you can see above, the image size was reduced to 24.9 MB. You can start the container and it will behave in the same manner. The docker-slim utility works well with Java, Python, Ruby, and Node.js application.

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

4. rocker: Breaks the limits of Dockerfile

Most of the developers using Docker use Dockerfile for building images. Dockerfile is a declarative way to define all the commands a user could call on the command line in order to assemble an image.

Rocker adds new instructions to the Dockerfile instruction set. Rocker was created by Grammarly to solve problems they faced with Dockerfile format. The Grammarly team wrote an in-depth blog explaining their reasons for creating it. I recommend you read it to better understand Rocker.  The two problems they highlight in their post are:

  1. Size of Docker images
  2. Slower builds

The blog also mentions some of the new instructions added by Rocker. Refer to Rocker documentation to learn about all the instructions Rocker supports.

  1. MOUNT is used to share volumes between builds so they can be reused by dependency management tools.
  2. FROM instruction exists in the Dockerfile as well. Rocker makes it feasible to add more than one FROM instruction. This means you can create more than one image from a single Rockerfile. The first set of instructions will build the artifact using all the dependencies. The second set of instructions can use the build artifact. This reduces the image size drastically.
  3. TAG is used to tag the image at different stages of the build. This means you don’t have to tag images manually.
  4. PUSH is used to push images to a registry.
  5. ATTACH allows you to run an intermediate step interactively. This is useful for debugging.

To use Rocker, you must install it on your machine. For Mac users, it is as simple as running couple of brew commands:

Docker utilities - rockerhttps://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1464px) 100vw, 1464px" data-recalc-dims="1" />

Once installed, you can use Rocker to build an image by passing it to Rockerfile:

Docker utilities - rockerhttps://i2.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i2.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i2.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1464px) 100vw, 1464px" data-recalc-dims="1" />

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

Docker utilities - rockerhttps://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1460px) 100vw, 1460px" data-recalc-dims="1" />

Rocker has good set of features. To learn more about it, refer to its documentation.

5. ctop: Top-like interface for containers

The utility I have started using lately is ctop, which provides a real-time metrics view of multiple containers. If you are a mac user, then you can install ctop using brew as shown below.

Docker utilities - ctophttps://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i1.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1452px) 100vw, 1452px" data-recalc-dims="1" />

Once installed, you can start using ctop. It only needs the DOCKER_HOST environment variable configured.

To view the state of all the containers, you can run `ctop` command.

Docker utilities - ctop https://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 300w, https://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 768w, https://i0.wp.com/blog.xebialabs.com/wp-content/uploads/2017/05/Screen-S... 1024w" sizes="(max-width: 1452px) 100vw, 1452px" data-recalc-dims="1" />

To view the running containers only, you can use `ctop -a` command.

The ctop is a simple utility and very useful to learn about containers running on your host. You can read more about it in the ctop documentation.

These are some of the Docker utilities I find useful. Do you use any Docker utilities in your daily work? If so, let us know in the comments section below.

The post 5 Docker Utilities You Should Know appeared first on XebiaLabs.

Read the original blog entry...

More Stories By XebiaLabs Blog

XebiaLabs is the technology leader for automation software for DevOps and Continuous Delivery. It focuses on helping companies accelerate the delivery of new software in the most efficient manner. Its products are simple to use, quick to implement, and provide robust enterprise technology.

Latest Stories
In the world of DevOps there are ‘known good practices’ – aka ‘patterns’ – and ‘known bad practices’ – aka ‘anti-patterns.' Many of these patterns and anti-patterns have been developed from real world experience, especially by the early adopters of DevOps theory; but many are more feasible in theory than in practice, especially for more recent entrants to the DevOps scene. In this power panel at @DevOpsSummit at 18th Cloud Expo, moderated by DevOps Conference Chair Andi Mann, panelists discussed...
Cloud-based disaster recovery is critical to any production environment and is a high priority for many enterprise organizations today. Nearly 40% of organizations have had to execute their BCDR plan due to a service disruption in the past two years. Zerto on IBM Cloud offer VMware and Microsoft customers simple, automated recovery of on-premise VMware and Microsoft workloads to IBM Cloud data centers.
Elon Musk is among the notable industry figures who worries about the power of AI to destroy rather than help society. Mark Zuckerberg, on the other hand, embraces all that is going on. AI is most powerful when deployed across the vast networks being built for Internets of Things in the manufacturing, transportation and logistics, retail, healthcare, government and other sectors. Is AI transforming IoT for the good or the bad? Do we need to worry about its potential destructive power? Or will we...
Many organizations adopt DevOps to reduce cycle times and deliver software faster; some take on DevOps to drive higher quality and better end-user experience; others look to DevOps for a clearer line-of-sight to customers to drive better business impacts. In truth, these three foundations go together. In this power panel at @DevOpsSummit 21st Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, industry experts will discuss how leading organizations build application success from all...
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
SYS-CON Events announced today that Daiya Industry will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Daiya Industry specializes in orthotic support systems and assistive devices with pneumatic artificial muscles in order to contribute to an extended healthy life expectancy. For more information, please visit https://www.daiyak...
The last two years has seen discussions about cloud computing evolve from the public / private / hybrid split to the reality that most enterprises will be creating a complex, multi-cloud strategy. Companies are wary of committing all of their resources to a single cloud, and instead are choosing to spread the risk – and the benefits – of cloud computing across multiple providers and internal infrastructures, as they follow their business needs. Will this approach be successful? How large is the ...
Your clients expect transactions to never fail, cloud access to be fast and always on, and their data to be protected - no exceptions. Hear about how Secure Service Container (SSC), an IBM-exclusive open technology, enables secure building and hosting of next-generation applications, both cloud and on-premises. SSC protects the full stack from external and insider threats, allows automatic encryption of data in-flight and at-rest, and is tamper-resistant during installation and runtime – with no...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
SYS-CON Events announced today that B2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
SYS-CON Events announced today that Interface Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Interface Corporation is a company developing, manufacturing and marketing high quality and wide variety of industrial computers and interface modules such as PCIs and PCI express. For more information, visit http://www.i...
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that Mobile Create USA will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Mobile Create USA Inc. is an MVNO-based business model that uses portable communication devices and cellular-based infrastructure in the development, sales, operation and mobile communications systems incorporating GPS capabi...
SYS-CON Events announced today that Nihon Micron will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nihon Micron Co., Ltd. strives for technological innovation to establish high-density, high-precision processing technology for providing printed circuit board and metal mount RFID tags used for communication devices. For more inf...