Operation Methods of Docker and Mirroring
- 2021-10-13 09:10:28
- OfStack
Find Mirror
We can search for mirrors from the website Docker Hub, and the website of Docker Hub is: https://hub.docker.com/
We can also use the docker search command to search for images. For example, we need an image of httpd as our web service. We can search httpd by using the docker search command to find the right image for us.
docker search httpd
Drag image
We decided to use the official version of httpd image shown above, using the command docker pull to download the image.
docker pull httpd
Delete Mirror
Image deletion uses the docker rmi command, for example, we delete hello-world images:
$ docker rmi hello-world
Create a mirror image
When the image we downloaded from the docker image repository does not meet our needs, we can make changes to the image in the following two ways.
1. Update the image from the container that has been created and submit the image
2. Use the Dockerfile directive to create a new image
Update image
Before updating the image, we need to use the image to create a container.
runoob@runoob:~$ docker run -t -i ubuntu:15.10 /bin/bash
root@e218edb10161:/#
Use the apt-get update command to update within the running container.
After completing the operation, enter the exit command to exit the container.
At this point, ID is the container of e218edb10161, which is changed according to our requirements. We can submit a copy of the container by commanding docker commit.
runoob@runoob:~$ docker commit -m="has update" -a="runoob" e218edb10161 runoob/ubuntu:v2
sha256:70bf1840fd7c0d2d8ef0a42a817eb29f854c1af8f7c59fc03ac7bdee9545aff8
Description of each parameter:
-m: Submitted description information -a: Specify Mirror Author e218edb10161: Container ID runoob/ubuntu: v2: Specify the target image name to create
Build a mirror image
We use the command docker build to create a new image from scratch. To do this, we need to create an Dockerfile file that contains a set of instructions to tell Docker how to build our image.
runoob@runoob:~$ cat Dockerfile
FROM centos:6.7
MAINTAINER Fisher "fisher@sudops.com"
RUN /bin/echo 'root:123456' |chpasswd
RUN useradd runoob
RUN /bin/echo 'runoob:123456' |chpasswd
RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" >/etc/default/local
EXPOSE 22
EXPOSE 80
CMD /usr/sbin/sshd -D
Each instruction creates a new layer on the image, and the prefix of each instruction must be uppercase.
Article 1 FROM, specifying which mirror source to use
The RUN directive tells docker to execute the command within the image and what is installed. . .
We then use the Dockerfile file to build a mirror with the docker build command.
runoob@runoob:~$ docker build -t runoob/centos:6.7 .
Sending build context to Docker daemon 17.92 kB
Step 1 : FROM centos:6.7
---> d95b5ca17cc3
Step 2 : MAINTAINER Fisher "fisher@sudops.com"
---> Using cache
---> 0c92299c6f03
Step 3 : RUN /bin/echo 'root:123456' |chpasswd
---> Using cache
---> 0397ce2fbd0a
Step 4 : RUN useradd runoob
......
Parameter description:
-t: Specifies the target image name to create
.: The directory where the Dockerfile file is located, and you can specify the absolute path to Dockerfile
Use docker images to see that the created image already exists in the list, and the image ID is 860c279d2fec
runoob@runoob:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
runoob/centos 6.7 860c279d2fec About a minute ago 190.6 MB
runoob/ubuntu v2 70bf1840fd7c 17 hours ago 158.5 MB
ubuntu 14.04 90d5884b1ee0 6 days ago 188 MB
php 5.6 f40e9e0f10c8 10 days ago 444.8 MB
nginx latest 6f8d099c3adc 12 days ago 182.7 MB
mysql 5.6 f2e8d6c772c0 3 weeks ago 324.6 MB
httpd latest 02ef73cf1bc0 3 weeks ago 194.4 MB
ubuntu 15.10 4e3b13c8a266 5 weeks ago 136.3 MB
hello-world latest 690ed74de00f 6 months ago 960 B
centos 6.7 d95b5ca17cc3 6 months ago 190.6 MB
training/webapp latest 6fae60ef3446 12 months ago 348.8 MB
We can use the new image to create the container
runoob@runoob:~$ docker run -t -i runoob/centos:6.7 /bin/bash
[root@41c28d18b5fb /]# id runoob
uid=500(runoob) gid=500(runoob) groups=500(runoob)
From the above, we can see that the new image already contains the user runoob created by us.
Set the image label
We can use the docker tag command to add a new label to the image.
runoob@runoob:~$ docker tag 860c279d2fec runoob/centos:dev
docker tag mirror ID, here 860c279d2fec, user name, mirror source name (repository name), and new label name (tag).
Using the docker images command, you can see that ID has one more label for the image of 860c279d2fec.
docker pull httpd
0