Docker process, image, container related commands

Docker

Docker commands

1.1 Process related commands

systemctl start docker    #启动docker服务
systemctl stop docker     #停止docker服务 
systemctl restart docker  #重启docker服务 
systemctl status docker   #查看docker服务状态
systemctl enable docker   #开机启动docker服务

1.2 Mirror related commands

1. View mirror: View all local mirrors

docker images   
# 查看所有镜像的id
docker images –q

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-nU5mpvCi-1680189494008) (C:\Users\lps\AppData\Roaming\Typora\typora-user-images\ image-20230330205532053.png)]

2. Search mirror: find the desired mirror from the network

#docker search 镜像名称
docker search  redis

3. Pull the image: Download the image from the Docker warehouse to the local. The format of the image name is name:version number. If the version number is not specified, it is the latest version. If you do not know the image version, you can go to the docker hub to search for the corresponding image. https://hub.docker.com/_/docker

#docker pull 镜像名称:版本号
docker pull redis:5.0 
docker pull centos:7
docker pull mysql:5.6  |  docker pull mysql:8.0.25 
docker pull tomcat:8
docker pull nginx

4. Delete mirror: delete local mirror

#docker rmi 镜像id
docker rmi `docker images -q`

1.3 Container related commands

1. Check the container

docker ps       # 查看正在运行的容器
docker ps –a    # 查看所有容器 (包括没有运行的容器)

2. Create and start the container

#docker run -it | -id --name=容器名称 镜像名称:版本 /bin/bash
docker run -it --name=c1 centos:7 /bin/bash   #创建并自动进入容器,当输入exit 退出容器并回到宿主机
docker -id --name=c2 centos:7				 #创建容器 但不进入容器

Parameter Description:

-i: keep the container running. Usually used with -t. After adding the two parameters of it, the container will automatically enter the container after it is created, and after exiting the container (execute the command exit), the container will automatically close

-t: Reassign a pseudo-input terminal for the container, usually used together with -i

-d: Run the container in daemon (background) mode. To create a container to run in the background, you need to use docker exec to enter the container. Container doesn't shut down after exiting

/bin/bash This means to run bash after loading the container. A process must be kept running in docker, otherwise the entire container will exit. This means that bash is started after starting the container. By default, a bash will be started, which can be ignored

3. Enter the container

#docker exec 参数  /bin/bash      #进入容器  注意 此处的/bin/bash不能省略
docker -id --name=c2 centos:7
docker exec -it c2 /bin/bash
exit         #此时容器还是在运行着的

4. Start the container

#docker start 容器名称
docker start c1

5. Stop the container from running

docker stop 容器名

6. Delete the container

#docker rm 容器名称       #如果容器是运行状态则删除失败,需要停止容器才能删除
docker rm c1

7. View container information

#docker inspect 容器名称
docker inspect  c1

8. View docker logs

#docker logs --tail 行数 -f  容器名   #查看某个容器末尾300行的日志内容
docker logs --tail  300 -f app-jar  

9. Docker container installation command

apt-get  update
apt-get  -y install net-tools  | yum .....

10. Used for data copy between container and host

#将主机/root/123.war文件拷贝到容器96f7f14e99ab的/root目录下
docker cp /root/123.war 96f7f14e99ab:/root/

#将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中
docker cp  96f7f14e99ab:/root /tmp/

Guess you like

Origin blog.csdn.net/lps12345666/article/details/129869281