栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

docker 常用命令(一)

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

docker 常用命令(一)

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 虚悬镜像: 仓库名和标签都是(没有仓库名和标签)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/747832.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号