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
SYS-CON Events announced today that Fusion, a leading provider of cloud services, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Fusion, a leading provider of integrated cloud solutions to small, medium and large businesses, is the industry’s single source for the cloud. Fusion’s advanced, proprietary cloud service platform enables the integration of leading edge solutions in the cloud, including cloud...
Five years ago development was seen as a dead-end career, now it’s anything but – with an explosion in mobile and IoT initiatives increasing the demand for skilled engineers. But apart from having a ready supply of great coders, what constitutes true ‘DevOps Royalty’? It’ll be the ability to craft resilient architectures, supportability, security everywhere across the software lifecycle. In his keynote at @DevOpsSummit at 20th Cloud Expo, Jeffrey Scheaffer, GM and SVP, Continuous Delivery Busine...
SYS-CON Events announced today that Cloud Academy will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud computing technologies. Ge...
While some vendors scramble to create and sell you a fancy solution for monitoring your spanking new Amazon Lambdas, hear how you can do it on the cheap using just built-in Java APIs yourself. By exploiting a little-known fact that Lambdas aren’t exactly single threaded, you can effectively identify hot spots in your serverless code. In his session at 20th Cloud Expo, David Martin, Principal Product Owner at CA Technologies, will give a live demonstration and code walkthrough, showing how to ov...
SYS-CON Events announced today that Interoute has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Interoute is the owner operator of Europe's largest network and a global cloud services platform, which encompasses over 70,000 km of lit fiber, 15 data centers, 17 virtual data centers and 33 colocation centers, with connections to 195 additional partner data centers. Our full-service Unifie...
Cloud promises the agility required by today’s digital businesses. As organizations adopt cloud based infrastructures and services, their IT resources become increasingly dynamic and hybrid in nature. Managing these require modern IT operations and tools. In his session at 20th Cloud Expo, Raj Sundaram, Senior Principal Product Manager at CA Technologies, will discuss how to modernize your IT operations in order to proactively manage your hybrid cloud and IT environments. He will be sharing bes...
SYS-CON Events announced today that Ocean9will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Ocean9 provides cloud services for Backup, Disaster Recovery (DRaaS) and instant Innovation, and redefines enterprise infrastructure with its cloud native subscription offerings for mission critical SAP workloads.
SYS-CON Events announced today that Systena America will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Systena Group has been in business for various software development and verification in Japan, US, ASEAN, and China by utilizing the knowledge we gained from all types of device development for various industries including smartphones (Android/iOS), wireless communication, security technology and IoT serv...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with the 21st International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. @ThingsExpo Silicon Valley Call for Papers is now open.
This talk centers around how to automate best practices in a multi-/hybrid-cloud world based on our work with customers like GE, Discovery Communications and Fannie Mae. Today’s enterprises are reaping the benefits of cloud computing, but also discovering many risks and challenges. In the age of DevOps and the decentralization of IT, it’s easy to over-provision resources, forget that instances are running, or unintentionally expose vulnerabilities.
SYS-CON Events announced today that Twistlock, the leading provider of cloud container security solutions, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Twistlock is the industry's first enterprise security suite for container security. Twistlock's technology addresses risks on the host and within the application of the container, enabling enterprises to consistently enforce security policies, monitor...
SYS-CON Events announced today that Enzu will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY, and the 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enzu’s mission is to be the leading provider of enterprise cloud solutions worldwide. Enzu enables online businesses to use its IT infrastructure to their competitive ad...
Everywhere we turn in our industry we can find strong opinions about the direction, type and nature of cloud’s impact on computing and business. Another word that is used in every context in our industry is “hybrid.” In his session at 20th Cloud Expo, Alvaro Gonzalez, Director of Technical, Partner and Field Marketing at Peak 10, will use a combination of a few conceptual props and some research recently commissioned by Peak 10 to offer a real-world consideration of how the various categories of...
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm. In his Day 3 Keynote at 20th Cloud Expo, Chris Brown, a Solutions Marketing Manager at Nutanix, will explore t...
SYS-CON Events announced today that SoftLayer, an IBM Company, has been named “Gold Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2016, at the Javits Center in New York, New York. SoftLayer, an IBM Company, provides cloud infrastructure as a service from a growing number of data centers and network points of presence around the world. SoftLayer’s customers range from Web startups to global enterprises.