Mirror && container
- docker mirror like operating system image (ISO)
- docker container is like running an installed operating system
So after docker image file up and running, it is what we call a docker container
Docker Image Operation
1) lists the mirror
docker image ls -a
Implementation of the results:
Parameter Description:
- REPOSITORY: warehouse where the name of the mirror
- TAG: image tag
- IMAGEID: Mirror ID
- CREATED: Creation Date mirrored (not the acquisition date of the mirror)
- SIZE: image size
In order to distinguish between different image in the same warehouse, Docker provides a feature called tag (Tag) is. When each mirror are listed with a label, e.g. latest, 12.10,12.04 like. Each tag for some specific mirror image layers labeled (for example, 12.04 is to mark all tags Ubuntu12.04 mirror layers). This mechanism enables a single repository can store multiple images. --- version number
When we run a warehouse with a different image, you can add the name of the warehouse behind a colon and the tag name to specify a specific image of the warehouse, such as docker run --name custom_container_name -i -t docker. io / ubunto: 12.04 / bin / bash, show that from the mirror Ubuntu: 12.04 start a container, and this is the mirror image of the operating system Ubuntu: 12.04. Designated warehouse in building the container label is a good habit.
2) pull the mirror
Docker mirrors is maintained at the warehouse, divided into private ownership and two kinds of common official repository Docker Hub (https://hub.docker.com/) is the most important and most common mirrors warehouse. Private warehouse (Private Registry) is the developer or corporate self-built image repository, usually used to store internal corporate Docker mirror, used to publish internal development processes and products, and version control.
To obtain a mirror, we can use the pull command, pulled from the mirror to a local warehouse, such as:
docker image pull library/hello-world
The above code, docker image pull crawl image file commands. library / hello-world is the location of the image file inside the warehouse, where the library is a set of image files are located, hello-world is the name of the image file
Since the image file Docker official of the group are placed inside the library, so it is the default group, it can be omitted. Thus, the above command can be written as follows.
docker image pull hello-world
3) remove the mirror
Image Docker RM image name or image id
Such as:
docker image rm hello-world
Docker Container Operation
1) Create a container
docker run [option] mirror name [incoming commands to start container]
Common Optional Parameters:
- -i expressed in "interactive mode" container
- -t represents the container after the start will enter its command line. After the addition of these two parameters, the vessel will be able to create log into. That is assigned a pseudo-terminal.
- --name name created for the container
- -v indicates mapping between the directory (directory of the former is the host, which is mapped to a directory on the host, i.e. the host directory: directory container), a plurality of a plurality of directories or files do -v mapping. Note: It is the directory for mapping, making changes on the host, and then to share the container.
- -d run behind the -d parameter will create a guardian of the container does not automatically logged container after (this container is created in the background, adding -i -t if only two parameters, it will automatically go to create a container ).
- It represents -p port mapping, the former is the host port, which is mapped in the port of the container. You can use multiple -p port mapping to do more
- -e container set environment variables
- --network = host-host mapping shows a network environment into the container, the container is the same as the host network
2) Interactive vessel
For example, to create an interactive container, and named myubuntu
docker run -it --name=myubuntu ubuntu /bin/bash
Free to execute linux commands in the container, is a ubuntu environment, when executing exit command to exit the container also will stop
3) container daemon
If for a long-term operation of the vessel , it is recommended to create a guardian of the container when the inner container exit to exit, the vessel will not stop
docker run -dit --name=myubuntu2 ubuntu
4) into the container already running
The first command docker exec -it container vessel name or id executed after entering
Such as:
docker exec -it myubuntu2 /bin/bash
5) Check container
# List the machine running container Docker Container LS # list all native container, including termination has been running Docker Container LS --all
6) Stop and start the container
# Stop an already running container docker container stop container vessel name or id # to start a container that has been stopped docker container start container vessel name or id container # kill off an already running in Docker Container the kill container vessel name or id
7) Delete container
Container Docker RM container vessel name or id
8) The holding vessel is a mirror image
Can be achieved through commit command
containers docker commit mirror name names
9) image backup and migration
Save command can be packaged into image file, copy to others to use
docker save -o file names saved image name
Such as:
docker save -o ./ubuntu.tar ubunt
After the image file to get, by the load method, the image is loaded into local
docker load -i ./ubuntu.tar
ending ~