Docker在Ubuntu上的安装及配置(基于k8s基础环境配置)

一、Docker安装

基于Ubuntu的安装及配置都完成后,点击跳转安装

1.安装必要的系统工具

bash 复制代码
root@ubuntu:~# apt-get -y install apt-transport-https ca-certificates curl software-properties-common

2.安装GPG证书

bash 复制代码
root@ubuntu:~# curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -

这里使用的是阿里云的docker软件源--->可以更换其他的docker软件源

3.写入docker-ce软件源信息

bash 复制代码
root@ubuntu:~# add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
E: Malformed entry 58 in list file /etc/apt/sources.list (Component)
E: The list of sources could not be read.
出现错误后,修正步骤:
root@ubuntu:~# sed -i '58d' /etc/apt/sources.list
root@ubuntu:~# sudo apt update

4. 更新并安装Docker

bash 复制代码
root@ubuntu:~# sudo apt-get update
root@ubuntu:~# apt-cache madison docker-ce
docker-ce | 5:19.03.9~3-0~ubuntu-focal | https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal/stable amd64 Packages   #安装5:19.03.9~3-0~ubuntu-focal版本,如果不使用k8s,可以不使用该版本--->我需要使用k8s
root@ubuntu:~# apt-get install -y docker-ce=5:19.03.9~3-0~ubuntu-focal
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 3035 (unattended-upgr)
N: Be aware that removing the lock file is not a solution and may break your system.
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
出现该提示错误时,修正步骤:(原因是apt被占用)
root@ubuntu:~# sudo killall apt apt-get unattended-upgr 2>/dev/null
root@ubuntu:~# sudo rm -f /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/lib/apt/lists/lock
root@ubuntu:~# sudo dpkg --configure -a
root@ubuntu:~# sudo apt-get install -y docker-ce=5:19.03.9~3-0~ubuntu-focal

二、Docker配置

我是为了支持k8s,之后做的一些基础配置,如果你实在不知道要做一些什么配置可以跟我一起做如下配置,不影响

1.查看docker-ce的信息:

bash 复制代码
root@ubuntu:~# docker info  #查看详细信息
如果结尾出现WARNING提示
表示你系统的docker-ce不支持swap,解决方式:
编辑:vim /etc/default/grup 文件
编辑行:GRUB_CMDLINE_LINUX="cgroup_enable=memony swapaccount=1"
更新,重启grap
update-grup
reboot

2.重启系统,配置iptables

bash 复制代码
root@ubuntu:~# reboot
临时方法:
root@ubuntu:~# iptables -P FORWARD ACCEPT
永久方法:
root@ubuntu:~# vim /lib/systemd/system/docker.service
在ExecReload=/bin/kill -s HUP $MAINPID之后
添加ExecStartPost=/sbin/iptables -P FORWARD ACCEPT
root@ubuntu:~# systemctl daemon-reload 
root@ubuntu:~# systemctl restart docker
root@ubuntu:~# iptables -L | less  #查看修改结果

3.自定义Docker加速器

bash 复制代码
root@ubuntu:~# cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors":["http://f1361db2.m.daocloud.io"],
"exec-opts":["native.cgroupdriver=systemd"],
"log-driver":"json-file",
"log-opts":{
"max-size":"100m"
},
"storage-driver":"overlay2"
}
EOF
root@ubuntu:~# systemctl daemon-reload
root@ubuntu:~# systemctl restart docker
root@ubuntu:~# docker info
Registry Mirrors:
  http://f1361db2.m.daocloud.io/
成功

4.关闭系统,拍摄快照

bash 复制代码
root@ubuntu:~# shutdown -h now
相关推荐
Waay1 小时前
图文详解|K8s Pod内部结构
docker·云原生·kubernetes
码点滴2 小时前
CRI-O选型与容器运行时标准
开发语言·人工智能·架构·kubernetes·cri-o
子建莫敌4 小时前
50 ubuntu22.04
ubuntu
r-t-H6 小时前
KVM虚拟化与Docker基础实践-第二章
阿里云·docker·容器
Lyra_Infra7 小时前
技术排查报告:Kubernetes Ingress 路由异常
docker·架构
木雷坞7 小时前
Home Assistant Docker Compose 升级失败排查:镜像、备份和设备映射
服务器·docker·home assisant
牛奶咖啡138 小时前
k8s容器编排技术实践——OpenEuler安装部署k8s
kubernetes·信创·containerd配置加速器·openeuler安装k8s·k8s的常见安装方式·彻底关闭swap·工作节点使用kubectl
深圳市九鼎创展科技8 小时前
九鼎创展 X7110 开发板(JH7110):国产 RISC-V 多媒体平台全解析
大数据·linux·人工智能·嵌入式硬件·ubuntu·risc-v
老码观察8 小时前
K8s 容器化部署的宿主机资源规划的踩坑实录
docker·容器·kubernetes
我是谁??8 小时前
【6】基于 Docker + YOLOv8 的模型部署实战(GTX1660S + Ubuntu22.04)
yolo·docker·容器