6

docker常用命令之帮助启动类命令和镜像命令 - 蜀道,难

 1 year ago
source link: https://www.cnblogs.com/malinyan/p/17383544.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

docker安装之后,启动时会报如下错误:

Job for docker.service failed because start of the service was attempted too often. See "systemctl status docker.service" and "journalctl -xe" for details. To force a start use "systemctl reset-failed docker.service" followed by "systemctl start docker.service" again.

根据这篇博客来修改:https://blog.csdn.net/Along_168163/article/details/124118833

帮助启动类命令

启动docker

systemctl start docker

停止docker

systemctl stop docker

image-20230425143921205

重启docker

systemctl restart docker

查看docker状态

systemctl status docker

image-20230425143814660

开机启动docker

systemctl enable docker

image-20230425144136884

查看docker概要信息

docker info

查看docker总体帮助文档

docker --help

查看dockert命令帮助文档

docker 具体命令 --help

列出本地主机上的镜像

docker images

image-20230425144908487

目前我的机子上只有一个hello-world镜像,上面那一栏各个意思如下

REPOSITORY -----> 表示镜像的仓库源
TAG -----> 镜像的标签版本号
IMAGE ID -----> 镜像ID
CREATED -----> 镜像创建时间
SIZE -----> 镜像大小

同一仓库源可以有多个TAG版本,代表这个仓库源的不同个版本,我们使用REPOSITORY::TAG来定义不同的镜像。
如果你不指定一个镜像的版本标签,例如你只使用ubuntu,docker将默认使用ubuntu:latest镜像

列出本地所有的镜像(含历史映像层)

docker images -a

image-20230426233232432

只显示镜像ID

docker images -q

image-20230426233513068

docker pull 镜像名字:TAG

没有TAG就是最新版,等价于

docker pull镜像名字:latest

注:阿里云不知道怎么回事,下载还是很慢,配置了网易的镜像,好多了。

vi /etc/docker

image-20230427154729705

进入daemon.conf

vim daemon.conf

​ 输入下面内容并保存

"registry-mirrors": ["http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn"]

重新加载配置信息及重启 Docker 服务

systemctl daemon-reload

systemctl restart docker

用这个镜像源下载好多了。

演示:下载ubuntu镜像

docker pull ubuntu

image-20230427155339377

查看镜像/容器/数据卷所占的空间

docker system df

image-20230427155404173

删除单个镜像

docker rmi -f 镜像ID

例如删除之前下载的ubuntu镜像

docker rmi -f 08d22c0ceb15

image-20230427155855141

删除多个镜像

docker rmi -f 镜像名1:TAG 镜像名2:TAG

例如删除ubuntu和redis

docker rmi -f ubuntu:latest redis:6.0.8

image-20230427155824688

删除全部镜像(做这一步的时候要小心,考虑清楚)

docker rmi -f $(docker images -qa)

搜索需要的镜像

网址:https://hub.docker.com

docker search [OPTIONS] 镜像名字

OPTIONS说明:--limit:只列出N个镜像,默认25个

docker search redis

image-20230428145423171

搜索出5个redis镜像

docker search --limit 5 redis

image-20230428145256118

参数 说明
NAME 镜像说明
DESCRIPTION 镜像说明
STARS 点赞数量
OFFICIAL 是否是官方的
AUTOMATED 是否是自动构建

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK