Mirroring operation Docker
Requires the presence of a corresponding mirror Docker before running local container, if the mirror does not exist locally, Docker pulls the mirror image from the warehouse.
Get a mirror
Get command from the Docker Mirror Mirror warehouse is docker pull. The command format is:
docker pull [选项][Docker Registry地址[:端口号]/]仓库名[:标签]
Specific options can be seen by docker pull --help command, here we talk about the format of the image name. Warehouse Docker mirror address: The address is typically <domain name / IP> [: port number]. The default address is Docker Hub. Warehouse name: as said before, here's the repository name is the name of a two-stage, namely <username> / <software name>. For Docker Hub, if you do not give the user name, the default for the library, which is the official image.
docker pull ubuntu:16.04
The above command is not given warehouse address Docker mirror, the mirror will therefore be acquired from Docker Hub. The image name is ubuntu: 16.04, and will therefore get the official image library / ubuntu 16.04 tags for warehouse mirror image.
Run-time image
With the image, we can start with this image-based and run a container. At the top of ubuntu: 16.04, for example, if we're going to start inside the bash and interactive operation, you can execute the following command.
docker run -it --rm ubuntu:16.04 bash
-it: These are two parameters, a -i: interactive operation, a terminal is -t.
--rm: This parameter is to say after the vessel exit will be deleted
ubuntu: 16.04: This refers to the use ubuntu: 16.04 mirroring basis starting container.
bash: image name is placed after the command, here we want to have an interactive shell, and therefore use the bash.
Finally, we pulled out of the container through the exit.
Listed Mirror
To list already downloaded the image, you can use docker image ls command. The list contains the warehouse name, label, image ID, creation time and space occupied.
docker image ls
See image space, the container, the volume occupied by the data.
docker system df
Warehouse names, labels are <none> called dangling mirror image (dangling image), such image is displayed
docker image ls -f dangling=true
Generally, dangling mirror has lost its value of existence, is free to delete, you can delete the following command
docker image prune
Delete local mirror
If you want to delete the local mirror, you can use docker image rm command in the format:
docker image rm [选项] <镜像1>[<镜像2>...]
Wherein <image> ID may be a mirror short, long ID mirror, or mirror image name summary.
Use docker image ls -q to configure docker image rm, so you can batch delete image you want to delete.
docker image rm $(docker image ls -q ubuntu) #删除所有仓库名为redis的镜像
Or remove all the ubuntu: 16.04 before the mirror:
docker image rm $(docker image ls -q -f before=ubuntu:16.04)
Docker container operations
Is a container or a group should, and they run independently operating mode environment. Corresponding to the virtual machine operating system can be understood as a set of simulation runs (provided the environmental and other operating system environments state), and running the above application.
Start container
There are two ways to start the container, one is based on image and start a new container, the container is further a termination state (stopped) restart.
Because the real Docker containers are lightweight, user can delete and create new container.
Create and start
docker run
Output a "Hello World", after the termination of the container.
docker run ubuntu:16.04 /bin/echo "Hello world"
Start container has been terminated
docker container start 或者 docker start
Start a bash terminal, allow user interaction.
docker run -t -i ubuntu:16.04 /bin/bash
Let -t Docker assigned a pseudo-terminal bound to the standard input and the container, -i standard container so that the input remains open. When the container is created using the docker run, run a standard operating in the background Docker comprising:
- Check whether there are specific local mirror, there is no downloaded from a public warehouse
- Use a mirror to create and launch container
- Assign a file system, and a mirror mounted on the outside layer of the read-only and writable layer
- Host bridge configuration from the host bridge interface to a virtual interface to the container
- Configuring an ip address from the address pool container
- Execution of the application specified by the user
- After completion of the implementation of the container is terminated
Background process
A lot of time, Docker need to run in the background rather than a direct result of the execution of the command output in the current host. In this case, it can be achieved by adding -d parameter.
If the parameter is not used to run -d container, such docker run hello-world will log printing console.
If operation parameter -d container, such docker run -d hello-world does not output a log, the container will print id (the output can be viewed docker logs);
Note: if the container will run for a long time, and it is docker run the specified command about, nothing to do with the -d parameter.
Stop running container
Docker container stop may be used to terminate the operation of a vessel. The container can be seen in the final state with docker container ls -a command. The container is terminated state can be restarted by docker container start command. Here, the container docker container restart command will terminate a running state, it is then restarted.
Into the container
When using the -d parameter, the container starts into the background, sometimes you need to enter the vessel to operate using the docker exec command into operation.
exec command -i -t parameter
docker exec behind can be followed by a number of parameters, which is the main explanation -i -t parameter.
When only the -i parameter, since there is no allocation of pseudo-terminals, the interface is not familiar Linux command prompt, the command execution results can still be returned. When used with -i -t parameter, you can see the familiar Linux command prompt.
docker exec -it 容器id /bin/bash
Export and import container
Export Container
If you want to export a container locally, you can use docker export command.
docker export 容器ID>导出文件名.tar
Import Container
Docker import may be used from the container and then introduced into the snapshot files for the mirror
cat 导出文件名.tar|docker import - 镜像用户/镜像名:镜像版本
Alternatively, you can import a directory or by specifying a URL
docker import http://study.163.com/image.tgz example/imagerepo
Delete container
Delete container
You can use docker container rm to remove a termination state in a container
docker container rm ubuntu:16:04
If you want to delete a container operation, you can add -f parameter. Docker sends SIGKILL to a container.
Clear All containers in the terminated state
You can view a docker container ls -a command including the termination of all state container has been created, if too many erasures can be a lot of trouble, use the following command to clean out all the container is terminated state.
docker container prune