Docker 基础 - 常用命令

本文介绍 Docker 的一些常用命令,以方便平时排查问题与日常学习所需。

查看 Docker 版本

docker version

$ docker version
Client: Docker Engine - Community
 Version:           20.10.24
 API version:       1.41
 Go version:        go1.19.7
 Git commit:        297e128
 Built:             Tue Apr  4 18:22:57 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.24
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.19.7
  Git commit:       5d6db84
  Built:            Tue Apr  4 18:21:02 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

查看 Docker 详细信息

docker info

$ docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.10.4-docker)

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 21
 Server Version: 20.10.24
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 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: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.4.268-1.el7.elrepo.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.805GiB
 Name: vm-docker
 ID: DKAL:ZJAA:Y2VK:N5EN:66JW:RKPQ:C4SF:2EY2:HHKO:TL2J:5GKI:FFCY
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://x8iz0cyl.mirror.aliyuncs.com/
 Live Restore Enabled: false

镜像搜索

docker search imageName

$ docker search nginx
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                        1222      [OK]       
bitnami/nginx                      Bitnami nginx Docker Image                      184                  [OK]
nginxinc/nginx-unprivileged        Unprivileged NGINX Dockerfiles                  144                  
nginxproxy/nginx-proxy             Automated nginx proxy for Docker containers …   132                  
nginxproxy/acme-companion          Automated ACME SSL certificate generation fo…   131                  
ubuntu/nginx                       Nginx, a high-performance reverse proxy & we…   112                  
nginx/nginx-ingress                NGINX and  NGINX Plus Ingress Controllers fo…   89                   
nginx/unit                         This repository is retired, use the Docker o…   64                   
nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter for NGINX and NGIN…   39                   
bitnami/nginx-ingress-controller   Bitnami Docker Image for NGINX Ingress Contr…   32                   [OK]
unit                               Official build of NGINX Unit: Universal Web …   25        [OK]       
nginxproxy/docker-gen              Generate files from docker container meta-da…   16                   
rancher/nginx-ingress-controller                                                   12                   
kasmweb/nginx                      An Nginx image based off nginx:alpine and in…   7                    
nginxinc/nginx-s3-gateway          Authenticating and caching gateway based on …   6                    
nginxinc/ingress-demo              Ingress Demo                                    4                    
nginx/nginx-ingress-operator       NGINX Ingress Operator for NGINX and NGINX P…   2                    
nginxinc/amplify-agent             NGINX Amplify Agent docker repository           1                    
nginx/nginx-quic-qns               NGINX QUIC interop                              1                    
nginxinc/nginmesh_proxy_debug                                                      0                    
nginxinc/mra-fakes3                                                                0                    
nginxinc/mra_python_base                                                           0                    
nginxinc/ngx-rust-tool                                                             0                    
nginxinc/nginmesh_proxy_init                                                       0

拉取镜像

docker pull imageName

$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

$ docker pull nginx:1.15
1.15: Pulling from library/nginx
743f2d6c1f65: Pull complete 
6bfc4ec4420a: Pull complete 
688a776db95f: Pull complete 
Digest: sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Status: Downloaded newer image for nginx:1.15
docker.io/library/nginx:1.15

列出本地镜像

docker images

$ docker images
REPOSITORY                                     TAG                                  IMAGE ID       CREATED       SIZE
springboot-web-demo                            0.0.1-SNAPSHOT                       e08ac0e87a58   3 weeks ago   492MB
<none>                                         <none>                               668e34e20709   3 weeks ago   492MB
<none>                                         <none>                               078cf51d1cb2   3 weeks ago   492MB
registry.cn-hangzhou.aliyuncs.com/mylibs/dev   springboot-web-demo-0.0.1-SNAPSHOT   6721e754ea77   3 weeks ago   492MB
jenkins/jenkins                                2.440.1                              dda9cfa9f451   4 weeks ago   462MB
jenkins/jenkins                                latest                               55860ee0cd73   2 years ago   442MB
supermanito/helloworld                         latest                               d0d4aeb91dbf   2 years ago   181MB
nginx                                          latest                               605c77e624dd   2 years ago   141MB
openjdk                                        17                                   5f94f53bbced   2 years ago   471MB
bitnami/jenkins                                2.303.1-debian-10-r29                01f2ad9a5d5a   2 years ago   575MB
nginx                                          1.15                                 53f3fd8007f7   4 years ago   109MB

镜像打标签

docker tag sourceImage:tag targetImage:tag

$ docker tag nginx:1.15 nginx:my-1.15

$ docker images | grep nginx
REPOSITORY                                     TAG                                  IMAGE ID       CREATED       SIZE
springboot-web-demo                            0.0.1-SNAPSHOT                       e08ac0e87a58   3 weeks ago   492MB
<none>                                         <none>                               668e34e20709   3 weeks ago   492MB
<none>                                         <none>                               078cf51d1cb2   3 weeks ago   492MB
registry.cn-hangzhou.aliyuncs.com/mylibs/dev   springboot-web-demo-0.0.1-SNAPSHOT   6721e754ea77   3 weeks ago   492MB
jenkins/jenkins                                2.440.1                              dda9cfa9f451   4 weeks ago   462MB
jenkins/jenkins                                latest                               55860ee0cd73   2 years ago   442MB
supermanito/helloworld                         latest                               d0d4aeb91dbf   2 years ago   181MB
nginx                                          latest                               605c77e624dd   2 years ago   141MB
openjdk                                        17                                   5f94f53bbced   2 years ago   471MB
bitnami/jenkins                                2.303.1-debian-10-r29                01f2ad9a5d5a   2 years ago   575MB
nginx                                          1.15                                 53f3fd8007f7   4 years ago   109MB
nginx                                          my-1.15                              53f3fd8007f7   4 years ago   109MB

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值