The best Docker mirroring Tutorial In 2024, In this tutorial you can learn Lists mirror list,Get a new mirror,Find Mirror,Pulling them Mirror,Create a mirror,Update image,Construction of the mirror,Set up a mirror tag,
When running the container, using a mirror if there is no local, the docker will automatically download from the docker image repository, the default is downloaded from Docker Hub public image source.
Now we come to learn:
We can use the mirror docker images to list on the local host.
w3big@w3big:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 14.04 90d5884b1ee0 5 days ago 188 MB php 5.6 f40e9e0f10c8 9 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 4 weeks ago 136.3 MB hello-world latest 690ed74de00f 6 months ago 960 B training/webapp latest 6fae60ef3446 11 months ago 348.8 MB
Description of each option:
REPOSTITORY: Warehouse represents a source mirror
TAG: Mirror Tags
IMAGE ID: Mirror ID
CREATED: Mirror Created
SIZE: image size
The same warehouse source can have multiple TAG, on behalf of the warehouse source different versions, such as ubuntu warehouse source, there 15.10,14.04 and many different versions, we use REPOSTITORY: TAG to define different image.
So, if we want to use the version 15.10 of ubuntu system image to run the container with the following command:
w3big@w3big:~$ docker run -t -i ubuntu:15.10 /bin/bash root@d77ccb2e5cca:/#
If you want to use the version 14.04 of ubuntu system image to run the container with the following command:
w3big@w3big:~$ docker run -t -i ubuntu:14.04 /bin/bash root@39e968165990:/#
If you do not specify a mirrored version of the label, for example, you only use ubuntu, docker will default ubuntu: latest image.
When we use a mirror that does not exist on the local host Docker will automatically download the image. If we want to pre-download this image, we can use docker pull command to download it.
Cw3big@w3big:~$ docker pull ubuntu:13.10 13.10: Pulling from library/ubuntu 6599cadaf950: Pull complete 23eda618d451: Pull complete f0be3084efe9: Pull complete 52de432f084b: Pull complete a3ed95caeb02: Pull complete Digest: sha256:15b79a6654811c8d992ebacdfbd5152fcf3d165e374e264076aa435214a947a3 Status: Downloaded newer image for ubuntu:13.10
After the download is complete, we can directly use this image to run the container.
We can also use docker search command to search Mirror. For example, we need a mirror to httpd as our web services. We can search for httpd command docker search to find a mirror for us.
w3big@w3big:~$ docker search httpd
NAME: The name of the mirror warehouse source
DESCRIPTION: Mirror's description
OFFICIAL: Are docker official release
We decided to use httpd official version of the image above the mirror, use the command docker pull to download the image.
w3big@w3big:~$ docker pull httpd Using default tag: latest latest: Pulling from library/httpd 8b87079b7a06: Pulling fs layer a3ed95caeb02: Download complete 0d62ec9c6a76: Download complete a329d50397b9: Download complete ea7c1f032b5c: Waiting be44112b72c7: Waiting
After the download is complete, we can use a mirror.
w3big@w3big:~$ docker run httpd
When we downloaded from the docker mirror mirror warehouse does not meet our needs, we can image the following two ways to make changes.
w3big@w3big:~$ docker run -t -i ubuntu:15.10 /bin/bash root@e218edb10161:/#Using apt-get update command in the running of the vessel to be updated.
After completing the operation, enter the exit command to exit the container.
In this case the ID e218edb10161 container is a container according to our needs change. We can submit a copy of the container through a command docker commit.
w3big@w3big:~$ docker commit -m="has update" -a="w3big" e218edb10161 w3big/ubuntu:v2 sha256:70bf1840fd7c0d2d8ef0a42a817eb29f854c1af8f7c59fc03ac7bdee9545aff8
Various parameters:
-m: description of the information submitted
-a: Specifies the mirror Author
e218edb10161: Container ID
w3big / ubuntu: v2: Specifies the name of the target image to be created
We can see our new image w3big / ubuntu docker images using the command: v2:
w3big@w3big:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE w3big/ubuntu v2 70bf1840fd7c 15 seconds ago 158.5 MB ubuntu 14.04 90d5884b1ee0 5 days ago 188 MB php 5.6 f40e9e0f10c8 9 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 4 weeks ago 136.3 MB hello-world latest 690ed74de00f 6 months ago 960 B training/webapp latest 6fae60ef3446 12 months ago 348.8 MB
Use our new image w3big / ubuntu to start a container
w3big@w3big:~$ docker run -t -i w3big/ubuntu:v2 /bin/bash root@1a9fbdeb5da3:/#
We use the command docker build, from scratch to create a new image. To do this, we need to create a Dockerfile file, which contains a set of instructions to tell Docker how to build our image.
w3big@w3big:~$ cat Dockerfile FROM centos:6.7 MAINTAINER Fisher "fisher@sudops.com" RUN /bin/echo 'root:123456' |chpasswd RUN useradd w3big RUN /bin/echo 'w3big:123456' |chpasswd RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" > /etc/default/local EXPOSE 22 EXPOSE 80 CMD /usr/sbin/sshd -D
Each command will create a new layer in the mirror, prefix each command must be uppercase.
The first FROM, specify which mirror source use
RUN Run command tells docker in the mirror, what is installed. . .
We then use Dockerfile file to build an image by docker build command.
w3big@w3big:~$ docker build -t w3big/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 w3big /en/en/en
Parameter Description:
-t: Specifies the name of the target image to be created
.: Dockerfile file directory, you can specify the absolute path Dockerfile
Use docker images to view the image has been created in the list exists, the mirror ID for 860c279d2fec
w3big@w3big:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE w3big/centos 6.7 860c279d2fec About a minute ago 190.6 MB w3big/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 mirror to create the container
w3big@w3big:~$ docker run -t -i w3big/centos:6.7 /bin/bash [root@41c28d18b5fb /]# id w3big uid=500(w3big) gid=500(w3big) groups=500(w3big)
Seen from above the new image has been created that contains the user w3big us
We can use docker tag command for the mirror to add a new label.
w3big@w3big:~$ docker tag 860c279d2fec w3big/centos:dev
docker tag image ID, here is 860c279d2fec, user name, and the name of the source image (repository name) and a new tag name (tag).
Docker images can be seen using the command, ID is 860c279d2fec mirror one more label.
w3big@w3big:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE w3big/centos 6.7 860c279d2fec 5 hours ago 190.6 MB w3big/centos dev 860c279d2fec 5 hours ago 190.6 MB w3big/ubuntu v2 70bf1840fd7c 22 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 13 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