在 CentOS7 上安装 Docker

1.检查是否已经安装 docker

docker version

[rootalocalhost -]# docker wersion
bash: docker: command not found...

如果之前有安装先卸载

yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

2、检查系统信息

系统必须为64位:cat /etc/redhat-release

[rootalocalhost ~]# cat /etc/redhat-release
Cent0s Linux release 7.9.2009 (Core)

内核版本必须高于 3.10:uname -r

[rootalocalhost ~]# uname -r
3.10.0-1062.el7.x86 64

3、安装需要依赖库

yum update

yum install -y gcc gcc-c++

yum install -y yum-utils

4、设置 yum 源

​
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
​
yum-config-manager --add-repo  https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

 阿里云的镜像速度比较快

启用稳定存储库:

yum-config-manager --enable docker-ce-nightly

禁用测试存储库:

yum-config-manager --disable docker-ce-test

5、安装 docker 引擎

查看可安装 docker 版本列表:

yum list docker-ce --showduplicates | sort -r

安装指定版本 docker:

yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

安装最新的 docker:

yum install docker-ce docker-ce-cli http://containerd.io

6、启动 docker

systemctl start docker

设置开机启动:

systemctl enable docker

7、查看 docker 版本

docker version

8、运行 hello-word 镜像验证 docker 引擎

docker run hello-world

9、其他命令

docker images

docker search [OPTIONS] 镜像名

docker pull 镜像名[:TAG]

列出当前正在运行的容器列表:docker ps [OPTIONS]
-a:列出当前正在运行的所有容器列表和以前运行过的容器列表;

-l:显示最近创建的容器;

-n:显示最近n个创建的容器;

-q:静默模式,只显示容器编号;

--no-trunc:不截断输出。


启动容器:docker start 容器名/容器ID

重启容器:docker restart 容器名/容器ID

容器停止退出:exit

容器不停止退出:ctrl + P + Q

停止当前正在运行的容器:docker stop 容器名/容器ID


强制停止当前正在运行的容器:docker kill 容器名/容器ID

删除已停止的容器:docker rm [OPTIONS] 容器ID
OPTIONS 参数列表:

-f:强制删除容器,包括正在运行的容器。

查看日志:docker logs -f -t --tail 显示行数 容器ID

OPTIONS 参数列表:

-t:加入时间戳;

-f:跟随最新的日志打印;

--tail 显示行数:显示最后多少行。

查看容器内的进程信息:docker top 容器ID



卸载 Docker 步骤:

1、卸载 docker 服务 
yum remove docker-ce docker-ce-cli http://containerd.io
2、删除镜像、容器和卷
rm -rf /var/lib/docker

rm -rf /var/lib/containerd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值