环境:
CentOS7
官方文档:
https://docs.docker.com/engine/install/centos/
步骤:
本次安装在root用户下操作,非root用户可根据实际情况在命令前添加sudo
1. 环境确认
查看系统内核为3.10及以上
# uname -r
3.10.0-957.21.3.el7.x86_64
查看系统版本,NAME="CentOS Linux" VERSION="7 (Core)"
# 系统版本
[root@master ~]# cat /etc/os-release
2. 查看及卸载docker旧版本
查看是否已安装docker
# docker --version
-bash: docker: command not found
command not fount:说明没有旧版本的docker。
如果已安装旧版本,执行以下命令卸载旧版本,否则不用执行卸载命令
# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
3. 安装必要的包
# yum install -y yum-utils
4.设置国内镜像仓库,例如:阿里云镜像仓库
# yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
5.安装docker
# yum install -y docker-ce docker-ce-cli containerd.io
6.查看docker版本信息
简洁的版本信息
# docker --version
详细的版本信息
# docker version
7. 启动docker
# systemctl start docker
8. 测试docker hello world程序
# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
看到Hello from Docker成功运行
9.查看docker镜像
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 10 months ago 13.3kB
10.设置开机自启动
# systemctl enable docker
11.卸载docker(谨慎执行)
如果要卸载docker,执行以下命令:
卸载依赖
# yum remove docker-ce docker-ce-cli containerd.io
移除资源目录
# rm -rf /var/lib/docker
完成! enjoy it!