Docker安裝完整流程

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ò)以下方式開啟。同理可以開啟各種測(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

# 開啟Docker服務(wù)
# systemctl daemon-reload && systemctl enable docker && systemctl start docker

5. 開戶遠(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
# 開啟遠(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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容