先天条件
在CentOS中安装Docker 需要满足以下几个条件:
-
CPU 必须为64位;
-
Linux 内核必须在 3.10版本以上。
可以使用 uname - a 命令获取 以上信息uname -a
-
确保 yum 包更新到最新
yum update
卸载docker旧版本
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
安装相关工具类
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
添加软件源信息
(由于国内访问不到docker官方镜像的缘故 通过aliyun的源来完成)
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新并安装 Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
开启Docker服务
sudo systemctl start docker
配置阿里云的docker镜像库
因为国内无法访问dockerhub 点我获取阿里云加速地址
在阿里云开通容器镜像服务拿到加速地址在执行以下命令:
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["阿里云加速地址"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
验证docker
sudo docker run hello-world
出现以下内容则表示安装成功:
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for hello-world:latestHello from Docker!
This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the “hello-world” image from the Docker Hub.
(amd64)- The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.- The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
查看docker版本号
sudo docker version
官方安装地址
https://docs.docker.com/install/linux/docker-ce/centos/