# 05)idea连接远程docker构建镜像

# 启动远程镜像服务

vim /usr/lib/systemd/system/docker.service
1
在ExecStart=/usr/bin/dockerd 后面加上-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
1
 -H fd:// --containerd=/run/containerd/containerd.sock
1

# 重新加载配置文件

sudo systemctl daemon-reload 
1

# 重新启动docker

sudo systemctl restart docker
1

# 启动远程镜像无法启动docker问题

一定要按照如下配置进行

  • 这个问题我花费了2个多小时解决。按照如下步骤可以开启远程访问。
  • 我google查过,找了很久找到解决方案。

场景:我按照上面的步骤配置后。启动docker报错。开启远程docker访问失败。

  • 报错一

image-20240101161735613

[root@VM-8-4-centos movie_service_compose]# sudo systemctl restart docker
Job for docker.service failed because start of the service was attempted too often. See "systemctl status docker.service" and "journalctl -xe" for details.
1
2
  • 报错二,查看镜像都报错。
[root@VM-8-4-centos movie_service_compose]# docker images
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
1
2
  • 报错三,启动停止也是报错。

# 解决

我的docker (opens new window)版本:

[root@VM-8-4-centos movie_service_compose]# docker -v
Docker version 24.0.7, build afdd53b
[root@VM-8-4-centos movie_service_compose]# 
1
2
3

参考网上的一个说明,docker开启远程访问的配置为:

  • 第一步:创建 /etc/docker/daemon.json 文件(如果已经存在则修改),加入以下内容:
vi /etc/docker/daemon.json
1
{
  "hosts" : ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"]
}
1
2
3
  • "unix:///var/run/docker.sock":unix socket,本地客户端将通过这个来连接 Docker Daemon。
  • "tcp://0.0.0.0:2375":tcp socket,表示允许任何远程客户端通过 2375 端口连接 Docker Daemon。

第二步:下面重启docker。

查看dockerd报错日志:

journalctl -u docker
1

有这么一行报错日志。

 dockerd[12747]: unable to configure the Docker daemon with file /etc/docker/daemon.json: 
the following directives are specified both as  a flag and in the configuration file: hosts: (from flag: [fd://], from file: [unix:///var/run/docker.sock tcp://0.0.0.0:2375])
1
2

经过查阅相关资料,官网文档上有说这个错误原因:

https://docs.docker.com/config/daemon/#use-the-hosts-key-in-daemonjson-with-systemd

简而言之,就是配置冲突。

解决方法:

修改docker.service文件

 vim /usr/lib/systemd/system/docker.service
1

删掉【service】单元中ExecStart中的-H参数,如图

image-20240101162437680

然后重启docker,问题解决。

Last Updated: 7/27/2024, 11:59:26 AM