Enable Docker Model Runner with default TCP port
In this step, we will learn how to enable the Docker daemon to listen for connections on a default TCP port. By default, the Docker daemon communicates via a Unix socket, which is more secure for local access. However, for remote access or specific use cases, enabling TCP can be necessary.
To enable the Docker daemon to listen on a TCP port, we need to modify its configuration file. The primary configuration file for Docker is typically located at /etc/docker/daemon.json
. If this file does not exist, you can create it.
First, let's check if the daemon.json
file exists. We can use the ls
command for this.
ls /etc/docker/daemon.json
If the file exists, the command will output its path. If it doesn't exist, you will see an error message indicating that the file or directory is not found.
Now, we will edit or create the /etc/docker/daemon.json
file using the nano
editor. We will add or modify the hosts
key to include the TCP address and port. The default TCP port for Docker is 2375 (unencrypted) or 2376 (TLS encrypted). For this step, we will use the unencrypted port 2375 for simplicity.
Open the file with nano
:
sudo nano /etc/docker/daemon.json
If the file was empty or did not exist, add the following content. If the file already had content, add or modify the hosts
key to include "tcp://0.0.0.0:2375"
. The unix:///var/run/docker.sock
entry ensures that the daemon still listens on the default Unix socket as well.
{
"hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"]
}
After adding or modifying the content, save the file by pressing Ctrl + X
, then Y
to confirm, and Enter
to write to the file name.
For the changes to take effect, you need to restart the Docker service. We can do this using the systemctl
command.
sudo systemctl restart docker
After restarting the Docker service, you can verify that it is listening on the TCP port by using the ss
command to check for listening sockets. We will look for a process listening on port 2375.
sudo ss -tuln | grep 2375
If the Docker daemon is successfully listening on port 2375, you should see output similar to this, indicating a process listening on that port:
tcp LISTEN 0 4096 0.0.0.0:2375 0.0.0.0:*
This confirms that the Docker daemon is now accessible via TCP on port 2375.