Docker常用基础命令详解

Docker常用基础命令详解

欢迎关注博主公众号「Java大师」, 专注于分享Java领域干货文章, 关注回复「资源」, 免费领取全网最热的Java架构师学习PDF, 转载请注明出处 http://www.javaman.cn/docker/docker-basic-command

发布时间: 2021-4-22 9:11:33 作者: java大师

1、docker version 查看当前docker ce版本

[root@iZbp14ak3swm571msqxpohZ ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.0
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        7287ab3
 Built:             Tue Dec  8 18:57:35 2020
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          19.03.14
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       5eb3275d40
  Built:            Tue Dec  1 19:19:17 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
[root@iZbp14ak3swm571msqxpohZ ~]# 

2、docker images 查看系统镜像

[root@iZbp14ak3swm571msqxpohZ ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
redis        latest    6060df96cef3   3 months ago   104MB
nginx        latest    f6d0b4767a6c   4 months ago   133MB
mysql        5.7       697daaecf703   5 months ago   448MB
centos       latest    300e315adb2f   5 months ago   209MB
java         8         d23bdf5b1b1b   4 years ago    643MB

3、查看正在运行的容器

[root@iZbp14ak3swm571msqxpohZ ~]# docker ps
CONTAINER ID   IMAGE       COMMAND                  CREATED        STATUS        PORTS                                      NAMES
88d61b3ad7b9   nginx       "/docker-entrypoint.…"   7 weeks ago    Up 2 weeks    0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   my-nginx
11b5dbd336c8   mysql:5.7   "docker-entrypoint.s…"   3 months ago   Up 3 months   0.0.0.0:3306->3306/tcp, 33060/tcp          mysql

4、docker pull 获取镜像

[root@iZbp14ak3swm571msqxpohZ ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:5122f6204b6a3596e048758cabba3c46b1c937a46b5be6225b835d091b90e46c
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

5、docker run 镜像名称,启动该镜像

[root@iZbp14ak3swm571msqxpohZ ~]# docker run hello-world 

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

6、docker rm 删除容器

[root@iZbp14ak3swm571msqxpohZ ~]# docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS                      PORTS                                      NAMES
95fff9c6e1ab   hello-world   "/hello"                 46 seconds ago   Exited (0) 45 seconds ago                                              busy_heyrovsky
88d61b3ad7b9   nginx         "/docker-entrypoint.…"   7 weeks ago      Up 2 weeks                  0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   my-nginx
11b5dbd336c8   mysql:5.7     "docker-entrypoint.s…"   3 months ago     Up 3 months                 0.0.0.0:3306->3306/tcp, 33060/tcp          mysql
[root@iZbp14ak3swm571msqxpohZ ~]# docker rm 95fff9c6e1ab
95fff9c6e1ab
[root@iZbp14ak3swm571msqxpohZ ~]# docker ps -a
CONTAINER ID   IMAGE       COMMAND                  CREATED        STATUS                    PORTS                                      NAMES
88d61b3ad7b9   nginx       "/docker-entrypoint.…"   7 weeks ago    Up 2 weeks                0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   my-nginx
11b5dbd336c8   mysql:5.7   "docker-entrypoint.s…"   3 months ago   Up 3 months               0.0.0.0:3306->3306/tcp, 33060/tcp          mysql

7、docker rmi 镜像id或者镜像名称,删除镜像

[root@iZbp14ak3swm571msqxpohZ ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   2 months ago   13.3kB
redis         latest    6060df96cef3   3 months ago   104MB
nginx         latest    f6d0b4767a6c   4 months ago   133MB
mysql         5.7       697daaecf703   5 months ago   448MB
centos        latest    300e315adb2f   5 months ago   209MB
java          8         d23bdf5b1b1b   4 years ago    643MB
[root@iZbp14ak3swm571msqxpohZ ~]# docker rmi d1165f221234
Untagged: hello-world:latest
Untagged: hello-world@sha256:5122f6204b6a3596e048758cabba3c46b1c937a46b5be6225b835d091b90e46c
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
Deleted: sha256:f22b99068db93900abe17f7f5e09ec775c2826ecfe9db961fea68293744144bd
[root@iZbp14ak3swm571msqxpohZ ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
redis        latest    6060df96cef3   3 months ago   104MB
nginx        latest    f6d0b4767a6c   4 months ago   133MB
mysql        5.7       697daaecf703   5 months ago   448MB
centos       latest    300e315adb2f   5 months ago   209MB
java         8         d23bdf5b1b1b   4 years ago    643MB
上一篇:设置非root账号不用sudo直接执行docker命令


下一篇:oracle add_months()函数