- Creating a Boot Image
docker run
This command is the most commonly used command. It mainly uses the following options: ① -d: indicates background operation. ② -P (in uppercase) : indicates random port mapping.The host port is preceded by the container port, such asdocker run nginx -p 8080:80
, map port 80 of the container to port 8080 of the host, and then uselocalhost:8080
The nginx welcome page in the nginx container is displayed.The host directory is preceded by the container directory, such asdocker run -d -p 80:80 -v /dockerData/nginx/conf/nginx.conf:/etc/nginx/nginx.conf nginx
Mounted to the host/dockerData/nginx/conf/nginx.conf
File so that the host can pairnginx
If the host directory does not exist, it will be created automatically. ⑤–rm: Stop the container and delete it directlydocker run -d -p 80:80 --rm nginx
⑥–name: give the container a name, otherwise a long list of custom names will appeardocker run -name niginx -d -p 80:80 - nginx
- List the container
docker ps
This command lists the currently running containers, using-a
List all containers after the parameter (including stopped ones)
- Stop the container
docker stop
docker stop 5d034c6ea010
This is followed by the container ID, or you can use the container name - Start the stopped container
docker start
docker run
Create a new container and start it,docker start
Is a container for starting and stopping, such asdocker start 5d034c6ea010
- Restart the container
docker restart
This command is executed firstdocker stop
, and then executedocker start
, such asdocker restart 5d034c6ea010
- Into the container
Docker exec -it Container ID /bin/bash
如docker exec -it 5d034c6ea010 /bin/bash
, which is equivalent to accessing the operating system of the container itself - Remove the container
docker rm
如docker rm 5d034c6ea010
The container ID is followed by the need to stop the container before deleting it - Data copies
docker cp
This command is used to copy data between a container and a host, for exampledocker cp 5d034c6ea010: /etc/nginx/nginx.conf /dockerData/nginx/conf/nginx.conf
Copy the container directory file to the specified location on the host. The container ID can be replaced by the container name.