Docker开启远程访问 | 幸福的猪窝

Docker开启远程访问

Docker版本:18.06.1-ce
系统环境:Unbunt 18.04 LTS
Docker默认安装好后监听的是Linux的本地的/var/run/docker.sock 而,修改默认的配置文件 /etc/default/docker打开 DOCKER_OPTS后加上 -H tcp://0.0.0.0:2375 重启后发现并没有生效。 找了好多办法后终于一个测试后可用:

  1. 修改Docker的service脚本,位置在 /lib/systemd/system/docker.service.
  2. 新加一行 EnvironmentFile=/etc/default/docker
  3. 修改一行,在ExecStart这行末尾添加 $DOCKER_OPTS 注意在fd://后有个空格。 修改后部分如下:
1
2
3
4
5
6
[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
EnvironmentFile=/etc/default/docker
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS
ExecReload=/bin/kill -s HUP $MAINPID LimitNOFILE=1048576
  1. 修改后需要先执行 systemctl daemon-reload 重新加载内容是修改的脚本生效
  2. 重启Docker

    1
    systemctl restart docker
  3. 查看状态信息
    ~~~
    root@B85-HD3:/lib/systemd/system# systemctl status docker
    ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2018-09-10 11:09:28 CST; 35s ago Docs: https://docs.docker.com Main PID: 27814 (dockerd) Tasks: 34 CGroup: /system.slice/docker.service ├─27814 /usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 └─27836 docker-containerd –config /var/run/docker/containerd/containerd.toml 9月 10 11:09:25 B85-HD3 dockerd[27814]: time=”2018-09-10T11:09:25.791273740+08:00” level=info msg=”pickfirstBalancer: HandleSubConnStateChange: 0xc42037d090, CONNECTING” module=grpc 9月 10 11:09:25 B85-HD3 dockerd[27814]: time=”2018-09-10T11:09:25.791519585+08:00” level=info msg=”pickfirstBalancer: HandleSubConnStateChange: 0xc42037d090, READY” module=grpc 9月 10 11:09:25 B85-HD3 dockerd[27814]: time=”2018-09-10T11:09:25.791542455+08:00” level=info msg=”Loading containers: start.” 9月 10 11:09:27 B85-HD3 dockerd[27814]: time=”2018-09-10T11:09:26.999988164+08:00” level=info msg=”Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option –bi 9月 10 11:09:27 B85-HD3 dockerd[27814]: time=”2018-09-10T11:09:27.583972117+08:00” level=info msg=”Loading containers: done.” 9月 10 11:09:27 B85-HD3 dockerd[27814]: time=”2018-09-10T11:09:27.936514243+08:00” level=info msg=”Docker daemon” commit=e68fc7a graphdriver(s)=overlay2 version=18.06.1-ce 9月 10 11:09:27 B85-HD3 dockerd[27814]: time=”2018-09-10T11:09:27.936642449+08:00” level=info msg=”Daemon has completed initialization” 9月 10 11:09:28 B85-HD3 dockerd[27814]: time=”2018-09-10T11:09:28.074213509+08:00” level=info msg=”API listen on [::]:2375” 9月 10 11:09:28 B85-HD3 systemd[1]: Started Docker Application Container Engine. 9月 10 11:09:28 B85-HD3 dockerd[27814]: time=”2018-09-10T11:09:28.074869259+08:00” level=info msg=”API listen on /var/run/docker.sock” [/code] 可以看到端口已经生效

  • 本文作者: Vincent Dong
  • 本文链接: 296.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!