View container
View container running
docker ps
View all containers
docker ps –a
View the last run of the container
docker ps -l
Check stop container
docker ps -f status=exited
Create and launch container
Start container (image-based startup)
docker run
Common parameters:
- -i: indicates the operating container
- -t: a rear container starts 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: named container created.
- -v: represents the directory mapping relationship (the former is the host directory, which is mapped to a directory on the host), you can use multiple -v do multiple directories or file mappings. 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 after creation container).
- -p: mapping the port, the former is a host port, which is mapped in the port of the container. You can use multiple -p port mapping to do more
Create a container (1) interactive mode
docker run -it --name = name of the mirror container Title: Label / bin / bash
Such as starting centos7:
Docker RUN -id --name mycentos7 CentOS: centos7.7.1908
Then we see the ps command, you can see the launch of the vessel was found, state to start state
Exit the current container
exit
(2) create the container type guard mode:
docker run -di --name = name of the mirror container name: Label
Login guard vessel way (into the interior of the container):
Docker Exec Expediting IT container name (or the container ID) / bin / bash
or
docker exec -it container name (or the container ID) sh
Stop and start the container
Stop the container:
docker stop container name (or the container ID)
Start container:
docker start container name (or the container ID)
File copy
You can use the cp command if we need to copy the file into the container
File or directory name docker cp container to be copied: a container directory
Files can also be copied from the container
docker cp container name: container directories need to copy the file or directory
Directory is mounted (map)
When we can create a container, the container directory in the directory are mapped host, so that we can modify the host file to a directory in order to influence the container.
Create a container add -v parameter back to the host directory: container, for example:
docker run -di -v /usr/local/myhtml:/usr/local/myhtml --name=mycentos3 centos:7
If you share a multi-level directory, insufficient permissions prompt may appear.
This is because the security module selinux CentOS7 authority of the ban, and we need to add parameters --privileged = true to solve the problem without permission mounted directory
View container IP address
We can see the vessel running the following command a variety of data
Name docker inspect container (container ID)
You can also perform the following command to direct output direct IP address
Inspect --format = Docker ' {} {} .NetworkSettings.IPAddress ' container name (container ID)
Delete container
Removes the specified container:
Name docker rm container (container ID)