title: Docker开启Remote API访问 tags: [“docker”, “Remote”,“SpringBoot”,“cicd”] date: 2022-04-19 draft: false

Docker开启Remote API访问

方法一

1、修改/usr/lib/systemd/system/docker.serviceConfiguration,在[Service]部分ExecStart后面添加Configuration。

-H tcp://0.0.0.0:2375

修改后如下:

[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 -H tcp://0.0.0.0:2375
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

2、Reload Configuration File

systemctl daemon-reload 
systemctl restart docker

方法二

修改Configuration

sudo vim /etc/default/docker

加入下面Configuration

DOCKER_OPTS="-H tcp://0.0.0.0:2375"

Reload Configuration File

sudo systemctl restart docker

方法三

修改Configuration Filedaemon.json

vim /etc/docker/daemon.json

加入下面Configuration

{
  "hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]
}

tcp socket,表示允许任何远程客户端通过 2375 端口连接 Docker Daemon。

unix,本地客户端将通过这个来连接 Docker Daemon。

Reload Configuration File

systemctl daemon-reload
systemctl restart docker

检查是否开启

ps -ef|grep docker

即可看到端口是否开启。