Access Docker socket via TCP
Find the config file
- On Linux, the Docker daemon configuration file is usually located at
/etc/docker/daemon.json
. - On Windows, the file is located at
C:\ProgramData\docker\config\daemon.json
. - If the file doesn’t exist, create it.
Edit config
Add the following configuration to the file:
{
"hosts": ["tcp://192.168.1.10:2375", "unix:///var/run/docker.sock"]
}
This tells Docker to listen on TCP port 2375 on IP (192.168.1.10) and on the Unix domain socket at /var/run/docker.sock
. Replace 192.168.1.10 with your LAN or VPN IP.
The last line in that file must NOT have a comma after it, if there are more lines in there than the hosts’ line then add a comma to the end of all of them except the last one e.g.
{
"live-restore": true,
"max-concurrent-downloads": 5,
"max-concurrent-uploads": 5,
"hosts": ["tcp://192.168.1.10:2375", "unix:///var/run/docker.sock"]
}
DON’T MAKE THIS ACCESSIBLE TO ALL INTERNET BY USING 0.0.0.0 for the IP.
- Restart the Docker daemon
- On Linux, you can restart the Docker daemon using the command
sudo systemctl restart docker
. - On Windows, you can restart the Docker daemon using the Docker Desktop application.
- On Linux, you can restart the Docker daemon using the command
Test the configuration
Run the following command to test if the Docker socket is accessible via TCP:
docker -H tcp://192.168.1.10:2375 version
This will give a sample output like this :
❯ docker -H tcp://192.168.192.10:2375 version
Client: Docker Engine - Community
Version: 23.0.1
API version: 1.42
Go version: go1.19.5
Git commit: a5ee5b1
Built: Thu Feb 9 19:46:32 2023
OS/Arch: linux/arm64
Context: default
Server: Docker Engine - Community
Engine:
Version: 23.0.1
API version: 1.42 (minimum version 1.12)
Go version: go1.19.5
Git commit: bc3805a
Built: Thu Feb 9 19:46:32 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.18
GitCommit: 2456e983eb9e37e47538f59ea18f2043c9a73640
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
That’s it! You have now set up the Docker socket to be accessible via TCP. Keep in mind that exposing the Docker daemon on a network socket can be a security risk, so make sure to properly secure the socket and limit access to it, such as over VPN only or on lan only.