Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enable TCP port 2375 for external connection to Docker

Enable TCP port 2375 for external connection to Docker

See this issue.
Docker best practise to Control and configure Docker with systemd.

  1. Create daemon.json file in /etc/docker:

     {"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]}
    
  2. Add /etc/systemd/system/docker.service.d/override.conf

     [Service]
     ExecStart=
     ExecStart=/usr/bin/dockerd
    
  3. Reload the systemd daemon:

     systemctl daemon-reload
    
  4. Restart docker:

     systemctl restart docker.service
    
@mafei-dev

This comment has been minimized.

Copy link

@mafei-dev mafei-dev commented Jan 1, 2020

thanks a lot. ๐Ÿ‘

@kdetony

This comment has been minimized.

Copy link

@kdetony kdetony commented Jan 22, 2020

nice !!! good job, validate for Centos7/8 and Fedora 3x

@azzerilla

This comment has been minimized.

Copy link

@azzerilla azzerilla commented Feb 16, 2020

Thanks! Worked on Ubuntu 18!

@PauloRobertTlss

This comment has been minimized.

Copy link

@PauloRobertTlss PauloRobertTlss commented Apr 13, 2020

show!.. Simples e eficaz!

@spedroza82

This comment has been minimized.

Copy link

@spedroza82 spedroza82 commented May 27, 2020

Gracias mil

@DKBgit

This comment has been minimized.

Copy link

@DKBgit DKBgit commented Jun 12, 2020

Thanks. Other solutions of changing only the daemon.json didnt work for me. Glad I found your article.

@ckvtvm-arch

This comment has been minimized.

Copy link

@ckvtvm-arch ckvtvm-arch commented Jun 19, 2020

thanks a lot. ๐Ÿ‘

I am not able to daemon-reload or restart after adding the below:
I a using ubuntu 16.04

[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

centy@L5PXPQN2:$ sudo systemctl edit docker
centy@L5PXPQN2:
$ systemctl daemon-reload
Failed to execute operation: Launch helper exited with unknown return code 1
centy@L5PXPQN2:~$ systemctl restart docker.service
Failed to add /run/systemd/ask-password to directory watch: Permission denied
Failed to restart docker.service: Launch helper exited with unknown return code 1
See system logs and 'systemctl status docker.service' for details.

@mrdavidsanders

This comment has been minimized.

Copy link

@mrdavidsanders mrdavidsanders commented Jul 22, 2020

thanks a lot. ๐Ÿ‘

I am not able to daemon-reload or restart after adding the below:
I a using ubuntu 16.04

[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

centy@L5PXPQN2:$ sudo systemctl edit docker centy@L5PXPQN2:$ systemctl daemon-reload
Failed to execute operation: Launch helper exited with unknown return code 1
centy@L5PXPQN2:~$ systemctl restart docker.service
Failed to add /run/systemd/ask-password to directory watch: Permission denied
Failed to restart docker.service: Launch helper exited with unknown return code 1
See system logs and 'systemctl status docker.service' for details.

You need to prepend those last 2 commands with "sudo".

@isaiahlg

This comment has been minimized.

Copy link

@isaiahlg isaiahlg commented Aug 4, 2020

๐Ÿ‘ ๐Ÿ™‡

@OlgaMaciaszek

This comment has been minimized.

Copy link

@OlgaMaciaszek OlgaMaciaszek commented Aug 17, 2020

๐Ÿ‘ โœ”๏ธ ๐Ÿ™‡โ€โ™€๏ธ

@edisonthk

This comment has been minimized.

Copy link

@edisonthk edisonthk commented Oct 7, 2020

๐Ÿ‘ โœ”๏ธ
working on
centos-release-7-8.2003.0.el7.centos.x86_64
Docker version 19.03.13, build 4484c46d9d
docker-compose version 1.27.0, build 980ec85b

@AndreSteenveld

This comment has been minimized.

Copy link

@AndreSteenveld AndreSteenveld commented Oct 8, 2020

This something I've tried as well and ran in to a few issues creating /etc/systemd/system/docker.service.d/override.conf, I am running Debian 10 and installed (and updated) docker using the script provided in the documentation. (Install using the convenience script)

After reloading the systemd daemon docker still failed to start, going to the log I noticed the following line: (getting the last few lines of the log sudo tail -n 100 /var/log/daemon.log

Oct  8 16:40:16 docker-host systemd[1]: Starting Docker Application Container Engine...
Oct  8 16:40:16 docker-host dockerd[675]: 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: (fro
m flag: [fd://], from file: [tcp://0.0.0.0:2375 unix:///var/run/docker.sock])
Oct  8 16:40:16 docker-host systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
Oct  8 16:40:16 docker-host systemd[1]: docker.service: Failed with result 'exit-code'.
Oct  8 16:40:16 docker-host systemd[1]: Failed to start Docker Application Container Engine.
Oct  8 16:40:18 docker-host systemd[1]: docker.service: Service RestartSec=2s expired, scheduling restart.
Oct  8 16:40:18 docker-host systemd[1]: docker.service: Scheduled restart job, restart counter is at 2.
Oct  8 16:40:18 docker-host systemd[1]: Stopped Docker Application Container Engine.

To get this to work I adding hosts to /etc/docker/daemon.json and editing /lib/systemd/system/docker.service (running sudo systemctl status docker.service reported the daemon being loaded from there) where I removed host provided in the start:

# Replacing this line:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

# With this line:
ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock

After which reloading the systemd daemon and restarting docker worked as a charm.

@tiensvanzyl

This comment has been minimized.

Copy link

@tiensvanzyl tiensvanzyl commented Nov 2, 2020

works great on Ubuntu 20.04 too thanks. Had to reboot the server though as only restarting docker.service did not work

@nurlanf

This comment has been minimized.

Copy link

@nurlanf nurlanf commented Nov 8, 2020

This something I've tried as well and ran in to a few issues creating /etc/systemd/system/docker.service.d/override.conf, I am running Debian 10 and installed (and updated) docker using the script provided in the documentation. (Install using the convenience script)

After reloading the systemd daemon docker still failed to start, going to the log I noticed the following line: (getting the last few lines of the log sudo tail -n 100 /var/log/daemon.log

Oct  8 16:40:16 docker-host systemd[1]: Starting Docker Application Container Engine...
Oct  8 16:40:16 docker-host dockerd[675]: 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: (fro
m flag: [fd://], from file: [tcp://0.0.0.0:2375 unix:///var/run/docker.sock])
Oct  8 16:40:16 docker-host systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
Oct  8 16:40:16 docker-host systemd[1]: docker.service: Failed with result 'exit-code'.
Oct  8 16:40:16 docker-host systemd[1]: Failed to start Docker Application Container Engine.
Oct  8 16:40:18 docker-host systemd[1]: docker.service: Service RestartSec=2s expired, scheduling restart.
Oct  8 16:40:18 docker-host systemd[1]: docker.service: Scheduled restart job, restart counter is at 2.
Oct  8 16:40:18 docker-host systemd[1]: Stopped Docker Application Container Engine.

To get this to work I adding hosts to /etc/docker/daemon.json and editing /lib/systemd/system/docker.service (running sudo systemctl status docker.service reported the daemon being loaded from there) where I removed host provided in the start:

# Replacing this line:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

# With this line:
ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock

After which reloading the systemd daemon and restarting docker worked as a charm.

Worked for Debian 10, thanks a lot ๐Ÿ‘

@PlusLibrary

This comment has been minimized.

Copy link

@PlusLibrary PlusLibrary commented Jan 15, 2021

Server side seems OK but I cant connect to the daemon from other machine:

C:\Users\Plus>docker -H tcp://192.168.3.2:2375 images
error during connect: Get https://192.168.3.2:2375/v1.40/images/json: http: server gave HTTP response to HTTPS client

I can get image list from browser with HTTP but I cannot use Docker Client (CLI) to access it

http://192.168.3.2:2375/v1.40/images/json

Can I force my Docker Client to NOT using HTTPS?
the docker environment is inside a private network so it maybe safe to not using SSL/HTTPS

@ZaharBozhok

This comment has been minimized.

Copy link

@ZaharBozhok ZaharBozhok commented Mar 25, 2021

If you are on mac you can just edit it in Docker -> Preferences -> Docker Engine (just add hosts and press apply & restart)
But if you are lucky and that gives you "Bad request" you can try editing in ~/.docker/daemon.json, that worked for me

@yuriy-slobodchikov

This comment has been minimized.

Copy link

@yuriy-slobodchikov yuriy-slobodchikov commented May 12, 2021

Thanks a lot! Centos 7.8

@LoesterFranco

This comment has been minimized.

Copy link

@LoesterFranco LoesterFranco commented May 26, 2021

thanks.

@sne4ky

This comment has been minimized.

Copy link

@sne4ky sne4ky commented Jun 1, 2021

Working on Manjaro 20.2.1 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment