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:
- 1. The management and use of the local host mirroring Docker
- 2. Create Mirror
Lists the mirror list
We can use docker images
to list the mirror present on the host computer.
root@:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 055936d39205 3 weeks ago 5.53MB
mysql 5.7 7faa3c53e6d6 3 weeks ago 373MB
ubuntu 15.04 d1b55fd07600 3 years ago 131MB
ubuntu 16.04 2a697363a870 2 weeks ago 119MB
Description of each option:
- REPOSITORY: represents the repository of the source image
- TAG: Mirror labels
- IMAGE ID: ID mirroring
- CREATED: image creation time
- 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 are several different versions 16.04,15.04, etc., we use REPOSITORY: TAG to define different image.
In a corresponding image starting container
If we want to use to run the container version 16.04 of ubuntu system image, the command is as follows:
root@ubuntu:~# docker run -it ubuntu:16.04 sh
If you are using version 15.04 of ubuntu system image, the command is as follows:
root@ubuntu:~# docker run -it ubuntu:15.04 sh
Each parameter parsing:
- docker: binaries Docker's.
- run: docker preceding run in combination with a container.
- -it: in fact, two parameters, -i and -t, -i: allows you to input standard (STDIN) in the container to interact. -t: Specifies a pseudo-terminal or terminals in the new container.
- ubuntu: 15.04 designated to run a mirror, Docker first from the local host mirroring exists, if does not exist, Docker will be downloaded from a mirror image of public warehouses Docker Hub.
- sh: execute the command.
Get a new image
When we use a mirror that does not exist in the host Docker will automatically download the image. If we want to pre-download this image, we can use the docker pull
command to download it.
root@ubuntu:~# docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
6abc03819f3e: Pull complete
05731e63f211: Pull complete
0bd67c50d6be: Pull complete
Digest: sha256:f08638ec7ddc90065187e7eabdfac3c96e5ff0f6b2f1762cf31a4f49b53000a5
Status: Downloaded newer image for ubuntu:18.04
After the download is complete, we can directly use this image to run the container.
Find Mirror
We can search image from Docker Hub website, Docker Hub site at: https://hub.docker.com/
We can also use the docker search
command to search for images. For example, we need a mirror image of httpd as our web service. We can docker search
to find the httpd command to search for our image.
- NAME: The name of the mirror warehouse sources
- DESCRIPTION: mirroring description
- OFFICIAL: Are docker official release
Mirrored pull httpd
We decided to use the official version of httpd mirror image above, use the command docker pull
to download the image.
root@ubuntu:~# docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
743f2d6c1f65: Already exists
c92eb69846a6: Pull complete
2211b052800a: Pull complete
aed180197314: Pull complete
7c472a4980a7: Pull complete
Digest: sha256:a35ad614c1ffc6fe931f12dc42b682edbdcc62cf78d8edc41499dd90ef0f8003
Status: Downloaded newer image for httpd:latest
After the download is complete, we can use this mirroring.
Create a mirror
When we downloaded from the docker Mirror Mirror warehouse can not meet our needs, we can make changes to the image in two ways.
- 1. Update the image from the container has been created, and submit this image
- 2. Use Dockerfile command to create a new image
Update image
Before the update image, we need to use a mirror to create a container.
root@ubuntu:~# docker run -it ubuntu:16.04 sh
Updated using the apt-get update command in the running container.
# apt-get update
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
Get:6 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [844 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
Get:10 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1237 kB]
Get:11 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]
Get:12 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [556 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [967 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [19.1 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [7942 B]
Get:17 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [8532 B]
Get:18 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [6113 B]
Fetched 15.8 MB in 8s (1933 kB/s)
Reading package lists... Done
After completing the operation, enter the exit command to exit the container.
By docker ps -a
viewing all containers:
root@ubuntu:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
12847d9f5071 ubuntu:16.04 "sh" 2 minutes ago Exited (0) 43 seconds ago peaceful_edison
3cec6f5e47c0 httpd "httpd-foreground" 5 minutes ago Exited (0) 5 minutes ago vigilant_heisenberg
At this point 12847d9f5071 container ID is container according to our needs change. We can submit a copy of the container from the command docker commit.
root@ubuntu:~# docker commit -m="has update" -a="yeqing112" 12847d9f5071 yeqing112/ubuntu:v2
sha256:5cce1167ee4c083ff9b87e61a58081805e76d015a12a4811bd152263aa013860
Various parameters:
- -m: description of the information submitted.
- -a: Specifies the mirroring of.
- 12847d9f5071: container ID.
- yeqing112 / ubuntu: v2: Specifies the name of the target image to be created.
We can use the docker images
command to view our new image yeqing112 / ubuntu: v2:
root@ubuntu:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yeqing112/ubuntu v2 5cce1167ee4c 2 minutes ago 144MB
ubuntu 16.04 2a697363a870 2 weeks ago 119MB
From the above information, we can see the updated image, some file size significantly larger than before.
Construction of Mirror
In addition to the method of updating image above, we can also use the command docker build
from scratch to build a new image. To this end, we need to create a Dockerfile file, which contains a set of instructions to tell Docker how to build our image.
root@ubuntu:~# cat Dockerfile
FROM ubuntu:16.04
MAINTAINER Fisher "[email protected]"
RUN apt-get update
EXPOSE 22
EXPOSE 80
CMD /bin/bash
Each command will create a new layer on the mirror, prefix each command must be capitalized.
The first FROM, which image to specify the source
RUN command tells docker execute commands in the mirror, what is installed
Here we are still the same, execute a apt-get update
update command
We then use Dockerfile file through docker build -t yeqing112/ubuntu:v3
Command to build a new image.
root@ubuntu:~# root@ubuntu:/home# docker build -t yeqing112/ubuntu:v3 .
Sending build context to Docker daemon 422.4kB
Step 1/6 : FROM ubuntu:16.04
---> 2a697363a870
Step 2/6 : MAINTAINER Fisher "[email protected]"
---> Running in 92229e7a091a
Removing intermediate container 92229e7a091a
---> 9a89f4debc7d
Step 3/6 : RUN apt-get update
---> Running in d709ef335784
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:5 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [844 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]
Get:10 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [556 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1237 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [967 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [19.1 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [7942 B]
Get:17 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [8532 B]
Get:18 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [6113 B]
Fetched 15.8 MB in 5s (3051 kB/s)
Reading package lists...
Removing intermediate container d709ef335784
---> 540751496556
Step 4/6 : EXPOSE 22
---> Running in 9ae528bc083f
Removing intermediate container 9ae528bc083f
---> cfccc621a52d
Step 5/6 : EXPOSE 80
---> Running in efd88e9349c1
Removing intermediate container efd88e9349c1
---> 428cb5221a06
Step 6/6 : CMD /bin/bash
---> Running in 2bc08b664f97
Removing intermediate container 2bc08b664f97
---> 9c55ea9b9ee8
Successfully built 9c55ea9b9ee8
Successfully tagged yeqing112/ubuntu:v3
Parameter Description:
- -t: Specifies the name of the target image to be created
- .: Dockerfile file directory, you can specify the absolute path Dockerfile
After building a successful, use docker images
View Mirror:
root@ubuntu:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yeqing112/ubuntu v3 9c55ea9b9ee8 9 seconds ago 144MB
yeqing112/ubuntu v2 5cce1167ee4c 16 minutes ago 144MB
ubuntu 16.04 2a697363a870 2 weeks ago 119MB
Seen from the above information, v2 and v3 new image file size is the same, the two mirrors are only performedapt-get update
Set up a mirrored label
We can use the docker tag
command to add a new label to the mirror.
root@ubuntu:/home# docker tag 9c55ea9b9ee8 yeqing112/ubuntu:v3-1
Mirror docker tag ID, here 9c55ea9b9ee8, the user name, source name mirror (repository name) and a new label name (tag).
Command using the docker images can be seen, ID is more than a mirror image of 9c55ea9b9ee8 v3-1 label.
root@ubuntu:/home# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yeqing112/ubuntu v3 9c55ea9b9ee8 21 minutes ago 144MB
yeqing112/ubuntu v3-1 9c55ea9b9ee8 21 minutes ago 144MB
yeqing112/ubuntu v2 5cce1167ee4c 38 minutes ago 144MB
ubuntu 16.04 2a697363a870 2 weeks ago 119MB