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

Introduction to the method of making mirror image by docker

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

Share

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

The main content of this article is "introduction to the method of making a mirror image of docker". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "introduction to the method of making docker into a mirror image".

There are generally three ways to make an image in docker: 1. Based on container production; 2. Based on dockerfile implementation, mirror production of the program file; 3.Docker Hub Automated Builds. Here we introduce how to make an image based on a container.

For example, start the clean image file busybox, then create the root directory of the httpd and the index.html file in the container, and then make a line image.

Launch the container with the name sunny01img

Docker run-it-- name sunny01img busybox:sunny01# is modified in the container / # mkdir-p / web/html/ # cd / web/html/web/html # vi index.htmlthis is sunny docker image,it is a nice day!

At the other terminal, execute the following command

Docker commit-a "sunny"-p-m "for test commit image" sunny01img

Use the command to view the newly generated image

Docker images

View the newly generated image with tag as none

Then push the image to the cloud service provider's image repository, and use the new image to start the container

Create a new label

Docker tag 3498bc48a842 websrv:sunnyweb01

Run the new mirror websrv:sunnyweb01 in daemon mode (- d, background), then specify the process as httpd, the front-end running mode (- f), and the home directory as / web/html

Docker run-- name sunnyweb01-d websrv:sunnyweb01 httpd-f-h / web/html

View

Docker ps

You can see that the websrv:sunnyweb01 image runs as a container sunnyweb01.

View process information

Docker top sunnyweb01

View detailed container information

Docker inspect sunnyweb01

View the current container ip and test the service of httpd

Change the default startup command for the container

Create the second version of the image based on the first version of the newly created image websrv:sunnyweb01. On another terminal, the default cmd is not executed, but the httpd service is started by default.

First, start the image, enter cmd, and execute the relevant commands.

Docker run-- name sunnyweb02-it websrv:sunnyweb01

Open another shell terminal and execute the following command to generate a new image

Docker commit-a "sunny"-p-m "web server"-c 'CMD ["/ bin/httpd", "- f", "- h", "/ web/html"]' sunnyweb02

Note-c, modify the running command, followed by a dictionary, all fields should be passed separately, separated by quotation marks and commas, otherwise the parameter transfer fails, resulting in the image cannot be started.

Sunnyweb02 refers to the name of the template container to be used as an image. For example, sunnyweb02 is used as a template to create a new image.

Tag the newly generated image and push the newly generated image to the cloud repository

Start the image, container name is web2.0, and run in the background (- d)

Test to see if the container is running properly

Docker ps

View the ip of the container

Docker inspect web2.0

Test the httpd service

This example shows that making an image can change the default command by-c instead of the default sh command, which allows the container to run the specified command based on the startup of the new image.

At this point, I believe you have a deeper understanding of the "introduction to the method of making a mirror image by docker". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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