适用于 CentOS Stream 9 的 Docker
·
✅ 一、系统准备
dnf update -y
dnf install -y yum-utils device-mapper-persistent-data lvm2 wget vim
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
✅ 二、内核与系统优化
#开启网络转发
cat > /etc/sysctl.d/docker.conf << EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
#提高资源限制
cat >> /etc/security/limits.conf << EOF
* soft nofile 655350
* hard nofile 1048576
* soft nproc 655350
* hard nproc 1048576
EOF
mkdir -p /etc/systemd/system/docker.service.d
cat > /etc/systemd/system/docker.service.d/limits.conf << EOF
[Service]
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
EOF
✅ 三、安装 Docker
yum-config-manager --add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl daemon-reexec
systemctl daemon-reload
systemctl enable --now docker
✅ 四、验证安装
docker -v
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://docker.1ms.run"]
}
EOF
systemctl daemon-reload
systemctl restart docker
docker info | grep -A 1 "Registry Mirrors"
docker run hello-world
登录官方镜像仓库(重构 Docker 的网络出口路径)
mkdir -p /etc/systemd/system/docker.service.d
cat > /etc/systemd/system/docker.service.d/http-proxy.conf << EOF
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890"
Environment="HTTPS_PROXY=http://127.0.0.1:7890"
EOF
systemctl daemon-reload
systemctl restart docker
docker login
#搜索官方仓库镜像
docker search nginx | head -5
#拉取镜像
docker pull tomcat:8-jdk8-corretto
#导出镜像
docker image save tomcat:8-jdk8-corretto > /opt/docker-images-tar/tomcat-8-jdk-corretto.tar.gz
#导入镜像
docker image load -i /opt/docker-images-tar/tomcat-8-jdk-corretto.tar.gz
#删除镜像
docker rmi tomcat:8-jdk8-corretto
#查看镜像详细信息
docker image inspect nginx:1.21
#阿里云镜像仓库使用
#退出官方镜像仓库
docker logout
# Step 2:登录私人阿里云镜像仓库
docker login --username=aliyun64123273 registry.cn-hangzhou.aliyuncs.com
#拉取私人阿里云镜像仓库镜像
docker pull registry.cn-hangzhou.aliyuncs.com/hujiaming/jiaming:[镜像版本号]
#上传镜像到私人阿里云镜像仓库
docker login --username=aliyun64123273 registry.cn-hangzhou.aliyuncs.com
docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/hujiaming/jiaming:[镜像版本号]
docker push registry.cn-hangzhou.aliyuncs.com/hujiaming/jiaming:[镜像版本号]
#删除本地所有未使用的镜像
docker image prune --all
更多推荐
所有评论(0)