Reducing Docker Image Sizes With Alpine Linux Images

The size of a Docker image affects its runtime and the performance of your application. Small containers run faster, are easier to manage, and take up less disk space.

There are several ways to reduce the size of Docker images. In particular, you can use Alpine Linux images which are much smaller than the rest.

4

Reduce the Size of an Existing Docker Image With Alpine

A Docker image is a template with instructions on how to builda Docker container. It has everything you need to set up and run an application. This may include dependencies, commands, and even environment variables.

There are two ways to reduceDockerimages withAlpineimages. One is by pulling an Alpine version of the image, and the second is by editingDockerfileto use anAlpineimage.

A cargo ship loaded with hundreds of colored shipping containers

Pull Docker Image From Docker Hub

Let’s pull anNginxDocker image and then reduce its size. Navigate to the Docker registry. From the official Docker images, pull aNginxImage with the following command:

Run the following command on the terminal to check whether the image is in your system.

downloaded nginx image 2

Notice the size of the downloadedNginximage is142MB. Next, let’s reduce the size of this image using anAlpine LinuxImage.

Alpine Linux is a very small distribution, so images based on it are small as well as simple and secure. Check the Docker registry for anNginximage version with theAlpinetag.

nginx  alpine image links

Then run the following command on the terminal:

Notice that now the size is smaller, almost a quarter of the initial image.

Docker image reduce size by Alpine 2

Edit Dockerfile to Use Alpine Images

Alternatively, edit theDockerfileof an existing application to use theAlpineimage.

Next, when you build the image with anAlpineimage, you will notice the size of thePythonimage has reduced.

Why Use Alpine Images?

Use Alpine images to reduce the size of Docker images quickly. Docker recommends the use of such official images for common use cases.

An Alpine Linux image creates small manageable containers in both development and production. It is easy to pull, configure, and use.

At the same time, it helps build and deploy lightweight applications across all platforms. It’s no wonder that Alpine is a developer-favorite Linux distro on the Docker platform.

Docker is becoming more popular, but why should you use it instead of a virtual machine?

Every squeak is your PC’s way of crying for help.

Unlock a world of entertainment possibilities with this clever TV hack.

Make sure you don’t miss these movies and shows before Netflix removes them.

You don’t need to fork out for expensive hardware to run an AI on your PC.

You can block out the constant surveillance and restore your privacy with a few quick changes.

Technology Explained

PC & Mobile