CentOS 7配置南大docker镜像

CentOS 7配置南大docker镜像

0.帮助页面

南大docker源:https://mirrors.nju.edu.cn/docker-ce/

南大docker源使用帮助:https://nju-mirror-help.njuer.org/docker-ce.html

官方安装文档:https://docs.docker.com/engine/install/

官方CentOS配置教程:https://docs.docker.com/engine/install/centos/

1.系统要求

  • 桌面级系统:
Platformx86_64 / amd64
Docker Desktop for Mac (macOS)
Docker Desktop for Windows
  • 服务器级系统
Platformx86_64 / amd64ARMARM64 / AARCH64
CentOS
Debian
Fedora
Raspbian
Ubuntu

2.卸载旧版本(没有旧版本可跳过)

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

如果没有旧版本仍输入此指令,则会提示none of these packages are installed

3.安装方式

根据官方文档,有3种可以使用的安装方式

对于一般用户来说只要选择第一种即可,即本文档的方式

4.准备工作

  • 安装yum-util包(非第一次安装可跳过)
sudo yum install -y yum-utils
  • 配置docker源

使用南大源,使用mirrors.nju.edu.cn/docker-ce

sudo yum-config-manager \
    --add-repo \
    https://mirrors.nju.edu.cn/docker-ce/linux/centos/docker-ce.repo

提示成功

Loaded plugins: fastestmirror, langpacks
adding repo from: https://mirrors.nju.edu.cn/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.nju.edu.cn/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
  • 更换南大源

从南大源上下载的docker-ce.repo与官方下载的是一样的,需要将文件内容中的download.docker.com也改成mirrors.nju.edu.cn/docker-ce

使用vim编辑配置文件

vim /etc/yum.repos.d/docker-ce.repo

按i进入编辑模式

按ESC退出编辑模式

退出编辑模式后按“:”进入命令模式

命令模式输入”%s/源字符串/目的字符串/g“批量替换

%s/download.docker.com/mirrors.nju.edu.cn\/docker-ce/g

输入后提示有24项被替换

南大源链接中有“/”字符,需要在其前面加上”\“字符转义

最后的参数g表示全局匹配,有其他的参数可自行百度

命令模式输入wq保存退出

5.可选操作

一般可以直接跳过这一步

选择docker版本(默认为stable)

docker有三种版本:stable,test和nightly

以下是官方对三种版本的介绍

Stable

Year-month releases are made from a release branch diverged from the master branch. The branch is created with format <year>.<month>, for example 18.09. The year-month name indicates the earliest possible calendar month to expect the release to be generally available. All further patch releases are performed from that branch. For example, once v18.09.0 is released, all subsequent patch releases are built from the 18.09 branch.

Test

In preparation for a new year-month release, a branch is created from the master branch with format YY.mm when the milestones desired by Docker for the release have achieved feature-complete. Pre-releases such as betas and release candidates are conducted from their respective release branches. Patch releases and the corresponding pre-releases are performed from within the corresponding release branch.

Nightly

Nightly builds give you the latest builds of work in progress for the next major release. They are created once per day from the master branch with the version format:

0.0.0-YYYYmmddHHMMSS-abcdefabcdef

where the time is the commit time in UTC and the final suffix is the prefix of the commit hash, for example 0.0.0-20180720214833-f61e0f7.

These builds allow for testing from the latest code on the master branch.

Note: No qualifications or guarantees are made for the nightly builds.

  • 使用nightly(默认关闭)
sudo yum-config-manager --enable docker-ce-nightly
  • 使用test(默认关闭)
sudo yum-config-manager --enable docker-ce-test
  • 手动关闭nightly
sudo yum-config-manager --disable docker-ce-nightly
  • 手动关闭test
sudo yum-config-manager --disable docker-ce-test

6.安装docker引擎

输入以下命令安装docker引擎

sudo yum install docker-ce docker-ce-cli containerd.io

中间会有提示验证GPG key,检查fingerprint是否为060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35,无误后输入y继续

如果需要安装指定版本,请在安装包后面添加版本名,即:

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

7. (可选)修改配置文件防止与xshell连接冲突

如果是在服务器上安装docker,那么可能需要进行此操作

原因我也没有详细了解过,只是在第一次安装后直接启动docker,发现启动后xshell连接立即中断,只能使用云平台的网页控制台才能连接

应该是网络服务上docker与xshell发生了一些冲突

网上资料:https://my.oschina.net/u/4337166/blog/3578106

网上原因分析(看不懂):

经排查,原来此环境windows机器的IP 为172.17.79.88,安装docker(1.13.0)后docker创建了一个虚拟网络桥连,恰好也使用了172.17.1.0/16的网段,172.17.79.88直接找到了docker的网段IP(172.17.0.1),而部署目标服务器IP,从而导致无法通过Xshell ssh上目标服务器!

既然找到了原因,我们就让docker避开172.17.18.0/24网段,改成172.20.1.0/16,也避免与一般的家用路由器IP段相撞。

解决方案如下:

  • 修改配置文件

修改第一个配置文件

vim /etc/default/docker

在文件中添加一行(我操作时文件不存在,即在vim中显示为空)

DOCKER_OPTS="--bip=172.20.1.0/16"

修改第二个配置文件

vim /etc/systemd/system/docker.service

如果文件没有内容,则退出后修改另一个文件,如果有内容则继续下一步

vim /lib/systemd/system/docker.service

在文件的[Service]选项中删除原来的EnvironmentFile和ExecStart,将以下内容添加到[Service]选项中,修改后如图所示

EnvironmentFile=-/etc/default/docker
ExecStart=/usr/bin/dockerd  $DOCKER_OPTS

image-20200922113527220

8.启动docker

  • 使用以下命令启动docker
sudo systemctl start docker

如果此时出现xshell断开连接的情况,请确认第7步没有问题。

如果依然第7步做完依然出现此情况,可以尝试输入reboot重启计算机再试

  • 使用以下命令测试docker
sudo docker run hello-world

出现以下输入说明docker配置成功

image-20200922115711575

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值