You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Docker服务名改为docker-ce?改名后docker.socket启动失败求助

重命名Docker服务后docker.socket启动失败的解决方法

问题场景

使用Kubespray部署Kubernetes集群时,默认会安装containerd作为容器运行时,但部分节点仍需保留Docker。由于Kubespray在安装containerd时会卸载检测到的docker.service,因此将docker.service重命名为docker-ce.service以规避卸载,但修改后docker.socket无法正常启动,报错如下:

[root@vm01234 system]# systemctl status docker.socket
● docker.socket - Docker Socket for the API
   Loaded: loaded (/usr/lib/systemd/system/docker.socket; enabled; vendor preset: disabled)
   Active: inactive (dead)
   Listen: /var/run/docker.sock (Stream)

Dec 09 16:47:04 vm01234 systemd[1]: docker.socket: Socket service docker.service not loaded, refusing.
Dec 09 16:47:04 vm01234 systemd[1]: Failed to listen on Docker Socket for the API.

当前运行环境为RHEL 8.6,现有服务及套接字配置如下:

docker.socket 配置

[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

docker-ce.service 配置

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[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/local/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# 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

解决步骤

  • 编辑docker.socket文件,在[Unit]段添加Service=docker-ce.service,明确指定套接字关联的服务名称:

    [Unit]
    Description=Docker Socket for the API
    Service=docker-ce.service  # 新增此行,指定socket对应的服务
    
    [Socket]
    ListenStream=/var/run/docker.sock
    SocketMode=0660
    SocketUser=root
    SocketGroup=docker
    
    [Install]
    WantedBy=sockets.target
    
  • 重新加载systemd配置,让修改生效:

    systemctl daemon-reload
    
  • 启动并设置开机自启docker-ce.service和docker.socket:

    systemctl enable --now docker-ce.service docker.socket
    
  • 验证服务状态,确认两者都正常运行:

    systemctl status docker-ce.service docker.socket
    

补充说明

修改后docker.socket会正确关联到docker-ce.service,不再出现启动失败的问题。同时需确认Kubespray的卸载逻辑仅针对docker.service,确保docker-ce.service不会被误卸载。


内容的提问来源于stack exchange,提问作者Mous

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 13:05:19