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 make a mirror image with docker

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the relevant knowledge of "docker how to make mirror image". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

Dockerfile is used to define the process of making an image, a script consisting of a series of commands and parameters that are applied to the base image and ultimately create a new image.

Sometimes, we want to modify or add files on the basis of the original image, but due to domestic network reasons, re-creating the image will be slow or even fail; or we don't know what the dockerfile of the image looks like. With minor changes, you can create a mirror image in the following way.

Take k8s Load Balancer component ingress-nginx:0.24.1 version as an example:

If we modify the source code and compile the nginx-ingress-controller binary file, we can make a new image in the following way.

First of all, use the command:

docker run -ti --rm k8s-deploy/nginx-ingress-controller:0.24.1 bash

Get the mirror running. Where-ti means to open an interactive input terminal;--rm means to automatically clean up after the operation stops.

After running, you can see that the default user is www-data, a298fe62a4f9 represents the container id

We can create directories in containers:

Re-open a shell window to copy a test file into the container:

docker cp ingressgroup-upstream.tmpl a298fe62a4f9:/etc/nginx/conf.d/include-server-map/

After copying in, when you want to move it to another location, report Permission denied insufficient permission, because the default is www-data user, ingressgroup-upstream.tmpl copied to the container belongs to the master: group is also root, if you do not modify root to www-data, you will definitely report no permission error.

Rerun mirroring by issuing the following command:

docker run -ti --rm -u 0 k8s-deploy/nginx-ingress-controller:0.24.1 bash

-u 0 represents running the container as root user, not the user specified in dockerfile. After running, you can see that the user is root, and the record container id: ffdc80 f3cce7

Repeat the copy operation:

At this point, you can freely move and modify the permissions of the file, belongs to the group, belongs to the owner.

Once the changes are complete, execute the following command to commit the mirror to the local repository:

docker commit ffdc80f3cce7 k8s-deploy/nginx-ingress-controller:0.24.1-temp

Commit is followed by the container id and the name of the new mirror. The push command pushes the new mirror to the remote harbor repository.

Run the newly created image and see the files we modified.

This method is generally used for testing, and the disadvantage is that it may lead to larger and larger mirrors.

The content of "docker how to make mirrors" is introduced here. Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

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

Internet Technology

Wechat

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

12
Report