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

How to build a docker image

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article shows you how to build a docker image, the content is concise and easy to understand, can definitely make your eyes bright, through the detailed introduction of this article, I hope you can learn something.

The best-case scenario for Docker users is that they do not need to create their own images. Almost all commonly used databases, middleware, applications, etc., have ready-made official Docker images or images created by other people and organizations, which we only need to configure to use directly.

The advantage of using ready-made mirror image is not only to save yourself the workload of doing mirror image, but also to make use of the experience of your predecessors. Use those official images in particular, because Docker engineers know how to better run software in containers.

Of course, in some cases, we also have to build our own images, such as:

I can't find a ready-made image, such as an application developed by myself.

Specific features need to be added to the image, such as the official image almost does not provide ssh.

So in this section we will show you how to build an image. At the same time, analyzing the construction process can also deepen our understanding of the previous mirror hierarchical structure.

Docker provides two ways to build an image:

Docker commit command

Dockerfile build file

Docker commit

The docker commit command is the most intuitive way to create a new mirror, which consists of three steps:

Run the container

Modify the container

Save the container as a new mirror

For example: install vi in the ubuntu base image and save it as a new image.

First step, run the container

The function of the-it parameter is to enter the container in interactive mode and open the terminal. 412b30588f4a is the internal ID of the container.

Install vi

The new mirror is named ubuntu-with-vi.

View the properties of the new mirror.

I can see from the size that the image has become larger because of the installation of the software.

Launch the container from the new image and verify that vi is ready to use.

The above demonstrates how to create a new image with docker commit. However, Docker does not recommend that users build images in this way. The reasons are as follows:

This is a way to create mirrors by hand, which is error-prone, inefficient and poorly repeatable. For example, to add vi to the debian base image, you have to repeat all the previous steps.

More importantly: users don't know how the image is created and whether there are malicious programs in it. In other words, the image cannot be audited, and there are security risks.

Since docker commit is not the recommended method, why should we take the time to learn?

The reason is that even if the image is built using Dockerfile (recommended method), the underlying docker commit will build a new image layer by layer. Learning docker commit can help us gain a deeper understanding of the build process and the hierarchical structure of the mirror.

The above is how to build a docker image. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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

Servers

Wechat

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

12
Report