The Docker image is the base of the container, and when you execute the Docker run it says to Docker which mirror I need now. If you do not have this image on your Docker host, Docker will automatically download the image from a registry (the Docker hub is the default)
In this section, we'll explore more about Docker images:
To list a local Docker image using the Docker images command
[[email protected] ~]# docker images repository TAG IMAGE ID CREATED sizedocker-whale latest 05bfcfec1909 7 days ago 252.7 mbdocker/docker-whale latest 05bfcfec1909 7 days ago 252.7 mbnginx latest e43d811ce2f4 2 weeks ago 181.4 MBubuntu latest f753707788c5 3 weeks ago 127.1 mb
You can see all the previously used mirrors, and by listing all the images, we can know three important information
There may be many different variants for a mirror in a mirrored warehouse, for example, for Ubuntu, we might find so many different variants of Ubuntu 10.04, 12.04, 12.10, 13.04, 13.10 and 14.04, So we'll use a tag to distinguish between different variants, as shown below
ubuntu:14.04
So, when you want to create a container, you can refer to the following to mark the image
$ docker run-t-I Ubuntu:14.04/bin/bash
If you want to create an Ubuntu 12.04 container, please refer to the following:
$ docker run-t-I Ubuntu:12.04/bin/bash
If you do not specify a label, we also use Ubuntu example, Docker will default to use Ubuntu:latest mirror
Tip: We should try to specify the mirror tag, such as ubuntu:14.04, so that we can know exactly which image we are using, which will be helpful for our later troubleshooting and debugging.
Now get a new image
$ docker Pull centosusing default tag:latestlatest:Pulling from Library/centosf1b10cd84249:pull completec852f6d61e65:p ull complete7322fbe74aa5:pull completedigest:sha256 : 90305c9112250c7e3746425477f1c4ef112b03b4abe78c612e092037bfecc3b7status:downloaded newer image for Centos:latest
Find a mirror
$ docker search sinatraname DESCRIPTION STARS OFFICIAL AUTOMATEDtraining/sinatra Sinatra training image 0 [OK]marceldegraaf/sinatra Sinatra test app 0mattwarren/docker-sinatra-demo 0. . .
If there's a mirror you need, you can pull it locally.
$ Docker Pull Training/sinatra
Create a mirror of our own
The image we download from the Docker hub may not fully meet our actual needs, we need to do some updates or modifications to him, we mainly update or modify a mirror in the following two ways:
First create a container $ docker run-t-I training/sinatra/bin/bash[email protected]:/#在容器内安装一些需要的软件包 [email protected]:/# apt-get Install-y Ruby2.0-dev ruby2.0 submits this container as a new mirror $ docker commit-m "Added json gem"-a "Kate Smith" 0b2616b0e5a8 Ouruser/sinatra : The container created by this image after V2 will have the software package installed above
First create a directory and a dockerfile$ mkdir sinatra$ cd sinatra$ Touch dockerfile write instructions to Dockerfile # This is a commentfrom ubuntu:14.04mai Ntainer Kate Smith <[email protected]>run apt-get update && apt-get install-y Ruby Ruby-devrun gem install Sinatra can then create your own custom mirrored $ Docker build-t Ouruser/sinatra:v2 via the build command.
Note: An image cannot exceed 127 layers at most, this is the global setting in which the overall size of the mirror is in a best state
Create your own Docker image