Ubuntu24.04 安装Docker
·
1. 参考
1.Install Docker Engine on Ubuntu
2.阿里云参考文档
2. 卸载已安装的Docker
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1)
3. 添加仓库
sudo apt update
sudo apt install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
3.1 使用官方仓库:
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update
3.2 使用阿里云仓库(推荐)
sudo curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] http://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
3.3 更新软件索引
sudo apt update
4. 安装Docker
4.1 安装软件
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
4.2 查看运行状态
- 启动服务
sudo systemctl start docker && sudo systemctl enable docker
- 查看状态
sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)
Active: active (running) since Mon 2025-12-15 10:04:33 CST; 1 day 6h ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 1144 (dockerd)
Tasks: 44
Memory: 142.6M (peak: 167.6M)
CPU: 7min 55.675s
CGroup: /system.slice/docker.service
├─ 1144 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
├─72828 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8899 -container-ip 172.20.0.3 -container-port 80 -use-liste>
└─72834 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8899 -container-ip 172.20.0.3 -container-port 80 -use-listen-fd
4.3 禁止自动升级
sudo apt-mark hold docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
docker-ce set on hold.
docker-ce-cli set on hold.
containerd.io set on hold.
docker-buildx-plugin set on hold.
docker-compose-plugin set on hold.
4.4 增加文件描述符软限制
- 修改docker服务systemd文件
vim /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target nss-lookup.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket
StartLimitBurst=3
StartLimitIntervalSec=60
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# 增加文件描述符软限制
LimitNOFILE=1048576
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500
[Install]
WantedBy=multi-user.target
- 加载并重启
systemctl daemon-reload
systemctl restart docker
4.5 添加配置文件
- 配置重启docker服务,不重启容器
- 配置镜像存储目录
- 配置私有仓库
- 配置镜像仓库
- 配置日志文件大小限制
[root@ubuntu24.04-18 ~]# vim /etc/docker/daemon.json
{
"live-restore": true,
"data-root": "/data/var/lib/docker",
"insecure-registries": ["192.168.6.5:5000"],
"registry-mirrors": [
"https://docker.xuanyuan.me",
"https://docker.m.daocloud.io",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
],
"log-driver": "json-file",
"log-opts": {
"max-size": "200m",
"max-file": "5"
},
"builder": {
"gc": {
"enabled": true,
"defaultKeepStorage": "20GB"
}
}
}
更多推荐
所有评论(0)