Docker安装完整流程

本文档详细介绍了如何在 CentOS 系统上卸载旧版 Docker,安装 Docker 仓库源,特别是使用阿里云镜像源加速下载,并配置 Docker 镜像加速。此外,还涵盖了开启远程连接端口的步骤,以及验证 Docker 安装是否成功的操作。提供了一个完整的安装脚本,方便快速部署。
摘要由CSDN通过智能技术生成


docker安装过程参考 Docker官方文档, 最后附完整的安装脚本

1. 卸载旧版本

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

2. 安装docker仓库源

2.1 官方仓库源(不推荐)

由于国内使用官方仓库源下载软件较慢,所以推荐使国内的镜像源,例如中科大、清华、阿里的镜像源,

# yum install -y yum-utils
# yum-config-manager --add-repo  https://download.docker.com/linux/centos/docker-ce.repo
2.2
# 安装必要的一些系统工具 
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

注意:

# 注意:
# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。
# 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服务
# systemctl daemon-reload && systemctl enable docker && systemctl start docker

5. 开户远程连接端口

# 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. 验证docker安装情况,执行 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
# 开启远程连接端口执行
# 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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值