Common basic commands of docker

(1) Basic commands of docker

1, start docker

systemctl start docker

2, close docker

systemctl stop docker 

3, restart docker

systemctl restart docker 

4, set docker to start automatically

systemctl enable docker

5. View the running status of docker (showing green means normal startup)

systemctl status docker 

(2) docker help command

1. If you forget to use some commands, you can view them

docker --help

Demonstration: If we forget to use the command when starting the image 

docker  run  --help

(3) docker image command

1, view the docker image list

docker  images

 

2, search for the mirror image alone

docker images image name 

 

 3. Pull the image  without tag (version number) to pull the latest version latest of the image in the docker warehouse. Add :tag to pull the specified version

docker pull image name 
docker pull image name: tag 

 Example: We pull a mysql without version number Here we pull the latest version latest

 

 Let's check to see if the pull is successful. As shown in the figure below, we successfully pulled

 4. Delete useless images

#Delete a
docker rmi -f mirror name/mirror ID

#Delete multiple mirror IDs or mirror images separated by spaces 
docker rmi -f mirror name/mirror ID mirror name/mirror ID mirror name/mirror ID

#Delete all images -a means to display all, -q means to only display the ID
docker rmi -f $(docker images -aq)

 force delete

docker image rm image name/image ID

 (3) docker container command

1. View running containers

docker  ps

2. View all containers including running and stopped containers 

docker  ps  -a

3. Run a container

# -it means to start interactively with the container -d means to run the container in the background (daemon running) --name The name of the container to be run /bin/bash interactive path
docker run -it -d --name to take Alias ​​image name: Tag /bin/bash  

 For example: we start a mysql5.7 version

docker  run -it  -d  --name  mysql mysql:5.7 /bin/bash

Then check the running container Here you can see that the mysql:5.7 container is running

docker  ps 

4. Access the container Here 5f39bcf1dbad is the container ID

docker  exec -it 5f39bcf1dbad /bin/bash 

 5. Delete the container First, stop the running container  

# First stop the mysql5.7 container we were running before 
docker stop container name/container ID

Then query all containers

docker ps -a 

#Delete a container
docker rm -f container name/container ID
#delete multiple containers spaces separate the container name or container ID to be deleted
docker rm -f container name/container ID container name/container ID container name/container ID
#delete All containers
docker rm -f $(docker ps -aq)

Container port to server port mapping

-p host port: container port 

-p 8080:8081 analysis Map the port 8081 inside the container with the port 8888 of the docker host (which server the docker is installed on is the host) port 8888, then you can access port 8081 of the docker container by accessing port 8080 of the host externally up 

docker run -it  -d --name mysql  -p 8888:6379 mysql:5.7 /bin/bash

Then run the container

docker exec -it public ID /bin/bash

Exiting the container is

exit or ctrl+p+q 

Guess you like

Origin blog.csdn.net/liujiahuan_/article/details/126222628
Recommended