Get the App
SLTechnology News&Howtos  ›  Servers  › 

Docker shares the code in which the container makes a mirror image.

Shulou Source: shulou.com Published: 2022-06-03 00:41:33 09月15日 Update

Today, Xiaobian shared with you the code that docker will mirror the container. I believe many people don't know much about it. In order to let everyone know more, I summarized the following contents for everyone. Let's look down together. I'm sure you'll find something.

Mirrors can be made by using the commit command or dockerfile. The commit command is relatively simple, equivalent to docker automatically generating dockerfile according to the command executed inside the container, and building it. It is more suitable for users who are unfamiliar with dockerfile;dockerfile is more suitable for batch processing scenarios.

Use docker commit command to mirror

1. pull a base image of centos 6.6 and run a docker container, then customize it (install, configure services, etc.);

[root@localhost ~]# docker pull centos:6.6Pulling repository centos8b44529354f3: Download completef1b10cd84249: Download completeStatus: Downloaded newer image for centos:6.6[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEcentos 6.6 8b44529354f3 4 days ago 202.6 MBcentos centos6.6 8b44529354f3 4 days ago 202.6 MB[root@localhost ~]# docker run -i -t centos:6.6 bash[root@b42c1ba929a9 /]# lsbin dev etc home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var[root@b42c1ba929a9 /]# mkdir /tmp/test.txt[root@b42c1ba929a9 /]# exitexit

Next, check out the container changes:

[root@localhost ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESb42c1ba929a9 centos:6.6 "bash" About a minute ago Exited (0) 22 seconds ago berserk_mcclintock804a56ce8008 f1b10cd84249 "/bin/echo hello" 22 minutes ago test[root@localhost ~]# docker diff b42c1ba929a9C /tmpA /tmp/test.txtC /rootA /root/.bash_history

2. Execute docker commit to create an image:

[root@localhost ~]# docker commit -m "new container" b42c1ba929a9 yuanhuan/newcontainer107b146e0be9e98c253122784c3837dd1604f7692e794f3601dad747d41901cd4[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEyuanhuan/newcontainer1 latest 07b146e0be9e 43 seconds ago 202.6 MBcentos 6.6 8b44529354f3 4 days ago 202.6 MBcentos centos6.6 8b44529354f3 4 days ago 202.6 MB

3. Log in to docker and push the image to the docker repository:

[root@localhost ~]# docker loginUsername: yuanhuanPassword:Email: yuanhuan_2005@126.comLogin Succeeded[root@localhost ~]# docker push yuanhuan/newcontainer1The push refers to a repository [yuanhuan/newcontainer1] (len: 1)Sending image listPushing repository yuanhuan/newcontainer1 (1 tags)f1b10cd84249: Image already pushed, skipping8b44529354f3: Image already pushed, skipping07b146e0be9e: Image successfully pushedPushing tag for rev [07b146e0be9e] on {https://cdn-registry-1.docker.io/v1/repositories/yuanhuan/newcontainer1/tags/latest} About docker will make the container mirror code to share here, I hope the above content can have a certain reference value for everyone, can learn to apply. If you like this post, share it with more people.

Tags: Mirror command code container content apply what you have learned next warehouse value scene foundation article way more user look automatically generate and will reference process Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker Xiaomi Shulou Technology macOS