目录

一、安装docker Engine:

第一步--准备工作

第二步--安装

二、卸载docker-Engine

三、安装后常见且重要的BUG


常用命令

journalctl -xeu docker.service 查看日志

sudo journalctl -u docker.service 查看日志

操作系统:Ubuntu 25.04

一、安装docker Engine:

第一步--准备工作

添加 Docker 的官方 GPG 密钥:

sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
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

将仓库添加到 Apt 源:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

#然后
sudo apt-get update

第二步--安装

指定版本安装

#列出可用版本 
apt-cache madison docker-ce | awk '{ print $3 }'
5:28.3.1-1~ubuntu.24.04~noble
5:28.3.0-1~ubuntu.24.04~noble
....

#选择版本
VERSION_STRING=5:28.3.0-1~ubuntu.24.04~noble

#安装
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin

或直接安装最新版本

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

二、卸载docker-Engine

 sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras

 sudo rm -rf /var/lib/docker
 sudo rm -rf /var/lib/containerd

 sudo rm /etc/apt/sources.list.d/docker.list
 sudo rm /etc/apt/keyrings/docker.asc

三、安装后常见且重要的BUG

1、systemctl start docker - Job for docker.service failed because the control process exited with error code

参考文章:systemctl start docker - Job for docker.service failed because the control process exited with error code - Stack Overflow

最可能的原因:/etc/docker/ 路径下的deamon.json 文件有问题,大概率是其中的内容配置有错误,改成正确配置格式或者直接把deamon.json删了就行。

2、request returned 500 Internal Server Error for API route and version http://%2Froot%2F.docker%2Fdesktop%2Fdocker.sock/v1.51/version, check if the server supports the requested API version

安装了 docker engineer又安装了docker desktop,把docker desktop卸载即可。

3、docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded

docker: Cannot connect to the Docker daemon at unix:///root/.docker/desktop/docker.sock. Is the docker daemon running?

参考文章:Fedora 36 - Docker - Cannot connect to the Docker daemon - Stack Overflow

解决办法:

(安装docker-engine后再安装docker-desktop)

  1. 卸载docker desktop

  2. 卸载 docker engine

  3. 删除 /root/.docker 这个隐藏的目录,或者是 /home/{username}/.docker(关键步骤)

  4. 按照安装指南重新安装 docker engine

  5. 将用户添加到 docker 组:

    #添加用户组
    sudo usermod -aG docker $USER
    #刷新用户组
    newgrp docker
    
  6. 重启电脑

  7. vim /etc/docker/daemon.json (没有这个文件就自己创建一个)

    daemon.json文件内容添加:

    {
    	"registry-mirrors" : [
    		"https://docker.registry.cyou",
    		"https://docker-cf.registry.cyou",
    		"https://dockercf.jsdelivr.fyi",
    		"https://docker.jsdelivr.fyi",
    		"https://dockertest.jsdelivr.fyi",
    		"https://mirror.aliyuncs.com",
    		"https://dockerproxy.com",
    		"https://mirror.baidubce.com",
    		"https://docker.m.daocloud.io",
    		"https://docker.nju.edu.cn",
    		"https://docker.mirrors.sjtug.sjtu.edu.cn",
    		"https://docker.mirrors.ustc.edu.cn",
    		"https://mirror.iscas.ac.cn",
    		"https://docker.rainbond.cc",
    		"https://do.nark.eu.org",
    		"https://dc.j8.work",
    		"https://dockerproxy.com",
    		"https://gst6rzl9.mirror.aliyuncs.com",
    		"https://registry.docker-cn.com",
    		"http://hub-mirror.c.163.com",
    		"http://mirrors.ustc.edu.cn/",
    		"https://mirrors.tuna.tsinghua.edu.cn/",
    		"http://mirrors.sohu.com/" 
    	],
     	"insecure-registries" : [
    	    "registry.docker-cn.com",
    	    "docker.mirrors.ustc.edu.cn"
        ],
    	"debug": true,
    	"experimental": false
    }
    

    重启daemon 然后重启 dockers服务

    sudo systemctl daemon-reload
    sudo systemctl restart docker
    docker info (检查)
    

    重新执行 docker run hello-world

重启电脑后如果出现下面错误:

docker run hello-world时报错
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": read tcp 192.168.30.91:51536->xxx.xxx.xxx.xxx(真实ip地址打码): read: connection reset by peer.

参考文章:docker配置镜像Docker pull时报错:https://registry-1.docker.io/v2/ - 知乎

解决办法参考上述 “步骤7”

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐