我是靠谱客的博主 深情鲜花,这篇文章主要介绍ubuntu18.04安装docker-ce国内源,现在分享给大家,希望可以做个参考。

ubuntu18.04安装docker-ce国内源

    • 修改国内加速源
    • 禁用防火墙
    • 永久禁用swap
    • 开启内核配置
    • 配置ipvs
    • 安装依赖包
    • 安装GPG证书
    • 写入docker源
    • 安装docker-ce
    • 配置国内镜像加速源
    • 设置docker服务开机自启

cka的考试环境是Ubuntu Server 18.04,所以还是选用了Ubuntu Server 18.04.

修改国内加速源

复制代码
1
2
3
4
5
6
7
8
# 备份源 cp /etc/apt/sources.list /etc/apt/sources.list.bak # 替换源地址为阿里云的地址 sed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list # 或 sed -i "s/cn.archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list

禁用防火墙

复制代码
1
2
3
# 禁用ufw防火墙 systemctl disable --now ufw

永久禁用swap

复制代码
1
2
3
4
5
6
# 永久禁用swap swapoff -a sed -ri 's/.*swap.*/#&/' /etc/fstab echo '禁用swap'

开启内核配置

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 开启配置内核参数 cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf overlay br_netfilter EOF # 加载br_netfilter网桥过滤模块 sudo modprobe overlay sudo modprobe br_netfilter echo '加载加载br_netfilter网桥过滤模块' cat <<EOF >/etc/sysctl.d/k8s.conf # 在ip6tables链中过滤IPv6包 net.bridge.bridge-nf-call-ip6tables = 1 # 是否在iptables链中过滤IPv4包 net.bridge.bridge-nf-call-iptables = 1 # 开启ipv4转发功能 net.ipv4.ip_forward = 1 net.ipv4.tcp_tw_recycle=0 # 禁用用swap vm.swappiness = 0 # 不检查物理内存是否够用 vm.overcommit_memory=1 # 开启OOM vm.panic_on_oom=0 fs.inotify.max_user_instances=8192 fs.inotify.max_user_watches=1048576 fs.file-max=52706963 fs.nr_open=52706963 # 禁用ipv6 net.ipv6.conf.all.disable_ipv6=1 net.netfilter.nf_conntrack_max=2310720 # 加大允许开启的线程数量 vm.max_map_count=262144 # 同一用户同时可以添加的watch数目 fs.inotify.max_user_watches = 524288 # 防止容器数量增加导致fs.inotify.max_user_instances超过限制 fs.inotify.max_user_instances = 1024 EOF # 使sysctl生效 sysctl --system

配置ipvs

参考: https://www.jianshu.com/p/cd7f18aacece

复制代码
1
2
3
4
5
6
7
8
9
10
11
apt install ipset ipvsadm -y # 临时加入ipvs的模块 for i in $(ls /lib/modules/$(uname -r)/kernel/net/netfilter/ipvs|grep -o "^[^.]*");do echo $i; /sbin/modinfo -F filename $i >/dev/null 2>&1 && /sbin/modprobe $i; done # 将需要启用的模块名写入 /etc/modules 系统启动时会自动加载 ls /lib/modules/$(uname -r)/kernel/net/netfilter/ipvs|grep -o "^[^.]*" >> /etc/modules ## 查看对应模块是否加载 lsmod | grep -e ip_vs -e nf_conntrack_ipv4

安装依赖包

复制代码
1
2
3
4
5
6
7
8
9
10
# 刷新源 sudo apt update # 安装依赖包 sudo apt install -y ca-certificates curl gnupg lsb-release

安装GPG证书

复制代码
1
2
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

写入docker源

链接:https://www.jianshu.com/p/3e0bdde3cce4

复制代码
1
2
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

安装docker-ce

复制代码
1
2
3
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io -y

配置国内镜像加速源

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
## 创建/etc/docker目录,创建docker存储目录 mkdir /etc/docker -p && mkdir /data/docker -p ## 配置存储目录 ### docker默认使用Cgroup Driver为cgroupfs,K8S推荐使用systemd来代替cgroupfs # 参考 https://v1-22.docs.kubernetes.io/zh/docs/setup/production-environment/container-runtimes/ cat <<EOF | sudo tee /etc/docker/daemon.json { "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "data-root": "/data/docker", "registry-mirrors": [ "https://isdp30x2.mirror.aliyuncs.com"] } EOF

设置docker服务开机自启

复制代码
1
2
3
4
5
6
7
8
## 重载服务 systemctl daemon-reload ## 重启docker服务 systemctl restart docker # 设置docker开机自启 systemctl enable docker

最后

以上就是深情鲜花最近收集整理的关于ubuntu18.04安装docker-ce国内源的全部内容,更多相关ubuntu18内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(112)

评论列表共有 0 条评论

立即
投稿
返回
顶部