docker安装详解
说明:本次使用的宿主机为阿里云服务器,发行版为Ubuntu22.04.4
1,配置linux内核流量转发功能
# 因为docker和宿主机的端口映射,本质是内核的流量转发功能
$ cat <<EOF > /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward=1
EOF
# 修改/etc/sysctl.d配置后,需要加载配置
service procps force-reload
# 加载内核防火墙模块,允许流量转发
modprobe br_netfilter
# 查看配置结果
lsmod | grep 'netfilter'
sysctl -a| grep 'bridge'
2,安装docker-ce社区版
# 卸载旧环境
apt-get remove docker docker-engine docker.io containerd runc
# 更新包
apt update
# 安装依赖包
apt install apt-transport-https ca-certificates curl gnupg lsb-release
apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release
# 添加阿里云Docker镜像源GPG秘钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# 更新包
apt update
# 安装docker服务
apt install docker-ce docker-ce-cli containerd.io
# 查看Docker是否启动成功
systemctl status docker
## 如果在执行Docker指令时,出现docker: permission denied while trying to connect to the...的错误提示,表示权限不足,需要执行切换root用户指令
3,配置国内镜像加速
# 配置阿里云镜像加速地址(json格式不能错)
mkdir -p /etc/docker
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://p1tr9vl1.mirror.aliyuncs.com"]
}
# 重启服务
systemctl daemon-reload
systemctl restart docker
4,测试docker安装完成
# 查找镜像hello-world
docker search hello-world
# 拉取镜像hello-world
docker pull hello-world
# 运行容器hello-world
docker run hello-wold
标签:bridge,apt,详解,镜像,world,docker,安装,hello
From: https://www.cnblogs.com/ctynlnlnl/p/18244176