docker常用命令之帮助启动类命令和镜像命令

2023-07-29,,

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

重启docker

systemctl restart docker

查看docker状态

systemctl status docker

开机启动docker

systemctl enable docker

查看docker概要信息

docker info

查看docker总体帮助文档

docker --help

查看dockert命令帮助文档

docker 具体命令 --help

镜像命令

列出本地主机上的镜像

docker images

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

REPOSITORY -----> 表示镜像的仓库源

TAG -----> 镜像的标签版本号

IMAGE ID -----> 镜像ID

CREATED -----> 镜像创建时间

SIZE -----> 镜像大小

同一仓库源可以有多个TAG版本,代表这个仓库源的不同个版本,我们使用REPOSITORY::TAG来定义不同的镜像。

如果你不指定一个镜像的版本标签,例如你只使用ubuntu,docker将默认使用ubuntu:latest镜像

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

docker images -a

只显示镜像ID

docker images -q

下载镜像

docker pull 镜像名字:TAG

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

docker pull镜像名字:latest

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

方法:

vi /etc/docker

进入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

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

docker system df

删除单个镜像

docker rmi -f 镜像ID

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

docker rmi -f 08d22c0ceb15

删除多个镜像

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

例如删除ubuntu和redis

docker rmi -f ubuntu:latest redis:6.0.8

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

docker rmi -f $(docker images -qa)

搜索需要的镜像

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

命令

docker search [OPTIONS] 镜像名字

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

docker search redis

搜索出5个redis镜像

docker search --limit 5 redis

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

docker常用命令之帮助启动类命令和镜像命令的相关教程结束。

《docker常用命令之帮助启动类命令和镜像命令.doc》

下载本文的Word格式文档,以方便收藏与打印。