docker 常用命令(一)

本文介绍了Docker的一些基本操作命令,包括启动、停止和重启Docker服务,查看Docker信息和帮助文档。还详细讲解了镜像相关命令,如查看本地镜像、搜索镜像、下载镜像以及查看镜像占用的磁盘空间。此外,提到了如何删除镜像以及清理Docker资源的注意事项。
摘要由CSDN通过智能技术生成

docker 常用命令(一)
1)帮助启动类命令
systemctl start docker 启动docker
systemctl stop docker 停止docker
systemctl restart docker 重启docker
systemctl status docker 查看docker状态
systemctl enable docker 设置开机启动docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

docker info查看docker简要信息
docker --help 查看docker帮助文档
docker cmd --help 查看docker命令帮助文档(具体的某个命令,比如run命令帮助文档:docker run --help)
查看docker cp命令帮助文档

[root@WIND ~]# docker cp --help

Usage:  docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
	docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

Copy files/folders between a container and the local filesystem

Use '-' as the source to read a tar archive from stdin
and extract it to a directory destination in a container.
Use '-' as the destination to stream a tar archive of a
container source to stdout.

Options:
  -a, --archive       Archive mode (copy all uid/gid information)
  -L, --follow-link   Always follow symbol link in SRC_PATH

2)docker镜像命令
docker images 查看本地镜像

[root@WIND ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   5 months ago   13.3kB

REPOSITORY 仓库
TAG代表版本号
IMAGE ID 镜像ID
CREATED 创建时间
SIZE镜像大小
同一个镜像可以有多个TAG(多个版本号)
一般使用REPOSITORY:TAG来定义不同的镜像
如果不指定,默认就使用LATEST,如nginx:latest

docker search 查找镜像

[root@WIND ~]# docker search nginx
NAME                                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
bitnami/nginx                                     Bitnami nginx Docker Image                      119                  [OK]
bitnami/wordpress-nginx                           Bitnami Docker Image for WordPress with NGINX   55                   [OK]
ubuntu/nginx                                      Nginx, a high-performance reverse proxy & we…   33
bitnami/nginx-ingress-controller                  Bitnami Docker Image for NGINX Ingress Contr…   16                   [OK]
rancher/nginx-ingress-controller                                                                  10
ibmcom/nginx-ingress-controller                   Docker Image for IBM Cloud Private-CE (Commu…   4
bitnami/nginx-ldap-auth-daemon                                                                    3
rancher/nginx-ingress-controller-defaultbackend                                                   2
circleci/nginx                                    This image is for internal use                  2
bitnami/nginx-exporter                                                                            1
rancher/nginx                                                                                     1
nginx                                             Official build of Nginx.                        0         [OK]
wallarm/nginx-ingress-controller                  Kubernetes Ingress Controller with Wallarm e…   0
rancher/nginx-conf                                                                                0
rancher/nginx-ssl                                                                                 0
ibmcom/nginx-ppc64le                              Docker image for nginx-ppc64le                  0
rancher/nginx-ingress-controller-amd64                                                            0
ibmcom/nginx-ingress-controller-ppc64le           Docker Image for IBM Cloud Private-CE (Commu…   0
rancher/nginx-proxy                                                                               0
bitnami/nginx-intel                                                                               0
wallarm/nginx-ingress-controller-amd64            Kubernetes Ingress Controller with Wallarm e…   0
ibmcom/nginx-ingress-controller-amd64                                                             0
ibmcom/nginx-ingress-controller-s390x                                                             0
kasmweb/nginx                                     An Nginx image based off nginx:alpine and in…   0
wallarm/nginx-amd64                                                                               0

我们可以看到有个offical那一列是带OK的,这个是官方认证的
一般用这个
如果觉得search出来的结果太多了,我们可以加–limit参数,不要那么多结果
[root@WIND ~]# docker search nginx --limit 10

docker pull 下载镜像

[root@WIND ~]# 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
默认下载最新版latest镜像
查看下载到的镜像
[root@WIND ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
nginx         latest    605c77e624dd   8 weeks ago    141MB
hello-world   latest    feb5d9fea6a5   5 months ago   13.3kB
[root@WIND ~]#docker pull nginx:1.16.0
1.16.0: Pulling from library/nginx
9fc222b64b0a: Pull complete
30e9fc7d9c5b: Pull complete
4b3a8aeaa40e: Pull complete
Digest: sha256:3e373fd5b8d41baeddc24be311c5c6929425c04cabf893b874ac09b72a798010
Status: Downloaded newer image for nginx:1.16.0
docker.io/library/nginx:1.16.0
指定nginx镜像版

docker system df 查看镜像/容器/数据卷所占的磁盘空间

[root@WIND ~]# docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          4         1         346.1MB   346.1MB (99%)
Containers      5         0         0B        0B
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B

Containers查看历史运行过多少个镜像

[root@WIND ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
我们docker ps看到一个正在运行的镜像都没,但是加-a参考就可以看到,确实是有5个
[root@WIND ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5edb0ed93c92 hello-world “/hello” About an hour ago Exited (0) About an hour ago cranky_noether
cd4154169336 hello-world “/hello” 5 hours ago Exited (0) 5 hours ago crazy_shtern
34ce13d1b457 hello-world “/hello” 6 hours ago Exited (0) 6 hours ago elegant_mclaren
269efecd4202 hello-world “/hello” 6 hours ago Exited (0) 6 hours ago happy_wescoff
1edfabfbc754 hello-world “/hello” 6 hours ago Exited (0) 6 hours ago hopeful_rosalind
[root@WIND ~]#

删除镜像
docker rmi 镜像名字:TAG
docker rmi IMAGEID1 IMAGEID2
删除镜像的2种方式
可以加-f参数把正在使用的镜像也删除
删除全部docker进行 docker rmi -f $(docker images -qa)
生产环境千万不要轻易用这个命令
-f是强制删除,把正在使用的镜像也删除掉
docker 虚悬镜像: 仓库名和标签都是(没有仓库名和标签)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值