Docker常用命令(按照a-z排序)

(1)attach    Attach to a running container  #当前shell下attach连接指定运行镜像  (这个命令启动后从容器中退出会关闭容器,使用ctrl+p+q退出容器,容器仍会运行)

root@lab01:/# docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
Deleted: sha256:f22b99068db93900abe17f7f5e09ec775c2826ecfe9db961fea68293744144bd


(2)build     Build an image from a Dockerfile  #通过Dockerfile定制镜像
(3)commit    Create a new image from a containers changes  #提交当前容器为新的镜像
(4)cp    Copy files/folders from a container to a HOSTDIR or to STDOUT  #从容器中拷贝指定文件或者目录到宿主机中
(5)create    Create a new container  #创建一个新的容器,同run 但不启动容器
(6)diff    Inspect changes on a containers filesystem  #查看docker容器变化
(7)events    Get real time events from the server#从docker服务获取容器实时事件
(8)exec    Run a command in a running container#在已存在的容器上运行命令(此启动方式退出后容器不会停止)

root@lab01:/# docker exec -it b3c05724e2cc /bin/bash
[root@b3c05724e2cc /]# exit
exit
root@lab01:/# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
b3c05724e2cc        centos              "/bin/bash"         6 minutes ago       Up About a minute


(9)export    Export a containers filesystem as a tar archive  #导出容器的内容流作为一个tar归档文件(对应import)
(10)history    Show the history of an image  #展示一个镜像形成历史
(11)images    List images  #列出系统当前镜像

root@lab01:/# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              d1165f221234        5 months ago        13.3kB
centos              latest              300e315adb2f        7 months ago        209MB


(12)import    Import the contents from a tarball to create a filesystem image  #从tar包中的内容创建一个新的文件系统映像(对应export)
(13)info    Display system-wide information  #显示系统相关信息

root@lab01:/# docker info
Containers: 1
 Running: 1
 Paused: 0
 Stopped: 0
Images: 1
Server Version: 20.10.7
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
 userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: e25210fe30a0a703442421b0f60afac609f950a3
runc version: v1.0.1-0-g4144b63
init version: fec3683 (expected: de40ad0)
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.15.0-136-generic
Operating System: Ubuntu 18.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.852GiB
Name: lab01
ID: QM6M:FR5E:SPCZ:MIW7:YTVQ:7CL7:AMPF:YJJQ:7SDG:UKUW:LLNU:AN7N
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support


(14)inspect    Return low-level information on a container or image  #查看容器详细信息
(15)kill    Kill a running container  #kill指定docker容器

root@lab01:/# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
b3c05724e2cc        centos              "/bin/bash"         14 minutes ago      Up 9 minutes                            example1
root@lab01:/# docker kill b3c05724e2cc
b3c05724e2cc
root@lab01:/# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS 


(16)load    Load an image from a tar archive or STDIN  #从一个tar包中加载一个镜像(对应save)
(17)login    Register or log in to a Docker registry#注册或者登陆一个docker源服务器
(18)logout    Log out from a Docker registry  #从当前Docker registry退出
(19)logs    Fetch the logs of a container  #输出当前容器日志信息

root@lab01:/# docker logs 55ba4e377056
[root@55ba4e377056 /]# echo hello     
hello


(20)pause    Pause all processes within a container#暂停容器

root@lab01:/# docker pause example1
example1


(21)port    List port mappings or a specific mapping for the CONTAINER  #查看映射端口对应的容器内部源端口
(22)ps    List containers  #列出容器列表

root@lab01:/# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
fc5bb16228bc        centos              "/bin/bash"         5 minutes ago       Exited (0) 16 seconds ago                       brave_goldberg
18a5fcc62fc2        hello-world         "/hello"            13 minutes ago      Exited (0) 13 minutes ago                       infallible_driscoll


(23)pull    Pull an image or a repository from a registry  #从docker镜像源服务器拉取指定镜像或者库镜像

root@lab01:/# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
7a0437f04f83: Pull complete 
Digest: sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Status: Downloaded newer image for centos:latest  


(24)push    Push an image or a repository to a registry  #推送指定镜像或者库镜像至docker源服务器
(25)rename    Rename a container  #重命名容器

root@lab01:/# docker rename example1 xiaochu
root@lab01:/# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
55ba4e377056        centos              "/bin/bash"         5 minutes ago       Up 2 minutes                            xiaochu


(26)restart    Restart a running container  #重启运行的容器

root@lab01:/# docker restart fc5bb16228bc 
fc5bb16228bc
root@lab01:/# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
fc5bb16228bc        centos              "/bin/bash"         4 minutes ago       Up 5 seconds                            brave_goldberg


(27)rm    Remove one or more containers  #移除一个或者多个容器  (删除容器时,容器需处于停止状态)

root@lab01:/# docker rm $(docker ps -a) #删除所有容器
fc5bb16228bc
brave_goldberg
18a5fcc62fc2


(28)rmi    Remove one or more images  #移除一个或多个镜像(无容器使用该镜像才可以删除,否则需要删除相关容器才可以继续或者-f强制删除)

root@lab01:/# docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
Deleted: sha256:f22b99068db93900abe17f7f5e09ec775c2826ecfe9db961fea68293744144bd


(29)run    Run a command in a new container  #创建一个新的容器并运行一个命令

root@lab01:/# docker run -it centos /bin/bash
[root@fc5bb16228bc /]# exit
exit


(30)save    Save an image(s) to a tar archive#保存一个镜像为一个tar包(对应load)
(31)search    Search the Docker Hub for images  #在docker hub中搜索镜像

root@lab01:/# docker search ubuntu
NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
ubuntu                                                    Ubuntu is a Debian-based Linux operating sys…   12574               [OK]                
dorowu/ubuntu-desktop-lxde-vnc                            Docker image to provide HTML5 VNC interface …   557                                     [OK]
websphere-liberty                                         WebSphere Liberty multi-architecture images …   276                 [OK]                
rastasheep/ubuntu-sshd                                    Dockerized SSH service, built on top of offi…   254                                     [OK]
consol/ubuntu-xfce-vnc                                    Ubuntu container with "headless" VNC session…   241                                     [OK]
ubuntu-upstart                                            Upstart is an event-based replacement for th…   113                 [OK]                
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          50                                      [OK]
open-liberty                                              Open Liberty multi-architecture images based…   47                  [OK]                
ubuntu-debootstrap                                        debootstrap --variant=minbase --components=m…   44                  [OK]                
i386/ubuntu                                               Ubuntu is a Debian-based Linux operating sys…   25                                      
solita/ubuntu-systemd                                     Ubuntu + systemd                                24                                      [OK]
1and1internet/ubuntu-16-apache-php-5.6                    ubuntu-16-apache-php-5.6                        14                                      [OK]
ppc64le/ubuntu                                            Ubuntu is a Debian-based Linux operating sys…   13                                      
1and1internet/ubuntu-16-apache-php-7.0                    ubuntu-16-apache-php-7.0                        13                                      [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10   ubuntu-16-nginx-php-phpmyadmin-mariadb-10       11                                      [OK]
1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4         ubuntu-16-nginx-php-5.6-wordpress-4             9                                       [OK]
1and1internet/ubuntu-16-nginx-php-5.6                     ubuntu-16-nginx-php-5.6                         8                                       [OK]
1and1internet/ubuntu-16-apache-php-7.1                    ubuntu-16-apache-php-7.1                        7                                       [OK]
darksheer/ubuntu                                          Base Ubuntu Image -- Updated hourly             5                                       [OK]
1and1internet/ubuntu-16-nginx-php-7.0                     ubuntu-16-nginx-php-7.0                         4                                       [OK]
1and1internet/ubuntu-16-nginx-php-7.1-wordpress-4         ubuntu-16-nginx-php-7.1-wordpress-4             3                                       [OK]
owncloud/ubuntu                                           ownCloud Ubuntu base image                      3                                       
1and1internet/ubuntu-16-sshd                              ubuntu-16-sshd                                  1                                       [OK]
1and1internet/ubuntu-16-php-7.1                           ubuntu-16-php-7.1                               1                                       [OK]
smartentry/ubuntu                                         ubuntu with smartentry                          1                                       [OK]


(32)8start    Start one or more stopped containers#启动容器

root@lab01:/# docker start fc5bb16228bc
fc5bb16228bc


(33)stats    Display a live stream of container(s) resource usage statistics  #统计容器使用资源

root@lab01:/# docker stats 55ba4e377056 
CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT    MEM %               NET I/O             BLOCK I/O           PIDS
55ba4e377056        xiaochu             0.00%               1.43MiB / 3.852GiB   0.04%               1.12kB / 0B         0B / 0B   


(34)stop    Stop a running container  #停止容器

root@lab01:/# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
fc5bb16228bc        centos              "/bin/bash"         3 minutes ago       Up 41 seconds                           brave_goldberg
root@lab01:/# docker stop fc5bb16228bc 
fc5bb16228bc
root@lab01:/# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES


(35)tag         Tag an image into a repository  #给源中镜像打标签
(36)top       Display the running processes of a container #查看容器中运行的进程信息

root@lab01:/# docker top xiaochu
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                413                 381                 0                   10:52               pts/0               00:00:00


(37)unpause    Unpause all processes within a container  #取消暂停容器

root@lab01:/# docker pause xiaochu
xiaochu
root@lab01:/# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                  PORTS               NAMES
55ba4e377056        centos              "/bin/bash"         9 minutes ago       Up 7 minutes (Paused)                       xiaochu
root@lab01:/# docker unpause xiaochu
xiaochu
root@lab01:/# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
55ba4e377056        centos              "/bin/bash"         10 minutes ago      Up 7 minutes                            xiaochu


(38)version    Show the Docker version information#查看docker版本号

root@lab01:/# docker version
Client:
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:49:01 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:54:48 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.9
  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3
 runc:
  Version:          1.0.1
  GitCommit:        v1.0.1-0-g4144b63
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683


(39)wait         Block until a container stops, then print its exit code  #截取容器停止时的退出状态值(阻塞运行直到容器停止,然后打印出它的退出代码。)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值