7 Tips to Optimize Your Docker Images


7 Tips to Optimize Your Docker Images

#1 Design Container Images for a Single Job

By focusing a container image for single job it will be focused and lightweight. Making a container image multi-purpose will bloat the size

#2 Install Required Packages Only

Install the bare minimum packages for the single job the image will be used for

#3 Reduce Number of Layers

Each RUN command creates a new layer. Combining the layers can reduce the image size. So, smart combinations of commands can lead to smaller images.

#4 Avoid Storing Application data

Storing application data in the container will balloon up your images. For production environments, always use the volume feature to keep the container separate from the data

#5 Avoid Using :latest

Using specific tags can ensure that you know the exact image being used from the Docker registry and don’t have any surprises if the :latest changes

#6 Sort Multi-line Arguments

Whenever you have a multi-line argument, sort the arguments alphanumerically to improve maintenance of the code. Haphazard arguments can lead to duplications. They are also harder to update

#7 Use .dockerignore

Use the .dockerignore to exclude unnecessary files and folders that complicate the build process and bloat the image

Optimizing Docker Images

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Using Docker Volumes to Share Data Between Containers and Host Computer

Docker volumes are used to persist data from a certain directory or directories of your Docker containers. So your data...

A Beginner’s Guide To Docker Compose

Docker Compose is one of the most useful tools for Software Developers and System Administrators. Many jobs require someone...

Install Docker on Debian 9

How to Install and Use Docker on Debian 9 Stretch Docker is a containerization system like LXC for virtualizing Linux operating...