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

posted @   Java大师-  阅读(201)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示