docker安裝過(guò)程參考Docker官方文檔, 最后附完整的安裝腳本
1. 卸載舊版本
# yum remove -y docker docker-client docker-client-latest docker-common \
docker-latest docker-latest-logrotate docker-logrotate docker-engine
2. 安裝docker倉(cāng)庫(kù)源
2.1 官方倉(cāng)庫(kù)源(不推薦)
由于國(guó)內(nèi)使用官方倉(cāng)庫(kù)源下載軟件較慢,所以推薦使國(guó)內(nèi)的鏡像源,例如中科大凶赁、清華埃跷、阿里的鏡像源,
# yum install -y yum-utils
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
2.2
# 安裝必要的一些系統(tǒng)工具
yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加軟件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
3. 安裝docker
yum makecache fast && yum -y install docker-ce
注意:
# 注意:
# 官方軟件源默認(rèn)啟用了最新的軟件嗜侮,您可以通過(guò)編輯軟件源的方式獲取各個(gè)版本的軟件包措左。例如官方并沒(méi)有將測(cè)試版本的軟件源置為可用赴肚,您可以通過(guò)以下方式開(kāi)啟。同理可以開(kāi)啟各種測(cè)試版本等鸟整。
# vim /etc/yum.repos.d/docker-ce.repo
# 將[docker-ce-test]下方的enabled=0修改為enabled=1
#
# 安裝指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
# Loading mirror speeds from cached hostfile
# Loaded plugins: branch, fastestmirror, langpacks
# docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
# docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable
# docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
# Available Packages
# Step2: 安裝指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
# sudo yum -y install docker-ce-[VERSION]
4. 配置docker鏡像加速
# mkdir -p /etc/docker
# tee /etc/docker/daemon.json << 'EOF'
{
"registry-mirrors": [
"https://1nj0zren.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://f1361db2.m.daocloud.io",
"https://registry.docker-cn.com"
]
}
EOF
# 開(kāi)啟Docker服務(wù)
# systemctl daemon-reload && systemctl enable docker && systemctl start docker
5. 開(kāi)戶遠(yuǎn)程連接端口
# sed -i 's#ExecStart=/usr/bin/dockerd#ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375#' /usr/lib/systemd/system/docker.service
# systemctl daemon-reload && systemctl restart docker
6. 驗(yàn)證docker安裝情況,執(zhí)行 docker run --rm hello-world
成功打印 Hello from Docker!
即為成功
[root@docker ~]# docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. 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 bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
[root@docker ~]#
7. 完整安裝腳本
#!/bin/bash
yum remove -y docker docker-client docker-client-latest docker-common \
docker-latest docker-latest-logrotate docker-logrotate docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
yum makecache fast && yum -y install docker-ce
mkdir -p /etc/docker
tee /etc/docker/daemon.json << 'EOF'
{
"registry-mirrors": [
"https://1nj0zren.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://f1361db2.m.daocloud.io",
"https://registry.docker-cn.com"
]
}
EOF
systemctl enable docker && systemctl start docker
# 開(kāi)啟遠(yuǎn)程連接端口執(zhí)行
# sed -i 's#ExecStart=/usr/bin/dockerd#ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375#' /usr/lib/systemd/system/docker.service
systemctl daemon-reload && systemctl restart docker
8.參考文檔
docker官方文檔: https://docs.docker.com/engine/install/centos/
aliyun docker repo: https://developer.aliyun.com/mirror/docker-ce