How to use docker desktop enable model-runner command to manage Model Runner settings

DockerDockerBeginner
Practice Now

Introduction

In this lab, you will learn how to manage Docker Model Runner settings using the model-runner command within Docker Desktop. We will cover enabling the Docker daemon to listen on a default TCP port, configuring it to listen on a custom TCP port, and finally, disabling the TCP connection for the Docker Model Runner.

Through hands-on steps, you will modify the Docker daemon configuration file (daemon.json) to control the network interfaces the daemon listens on, restart the Docker service to apply changes, and understand the implications of enabling or disabling TCP connections for remote access and security.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("Docker")) -.-> docker/ContainerOperationsGroup(["Container Operations"]) docker(("Docker")) -.-> docker/SystemManagementGroup(["System Management"]) docker/ContainerOperationsGroup -.-> docker/ls("List Containers") docker/ContainerOperationsGroup -.-> docker/restart("Restart Container") docker/SystemManagementGroup -.-> docker/system("Manage Docker") subgraph Lab Skills docker/ls -.-> lab-555140{{"How to use docker desktop enable model-runner command to manage Model Runner settings"}} docker/restart -.-> lab-555140{{"How to use docker desktop enable model-runner command to manage Model Runner settings"}} docker/system -.-> lab-555140{{"How to use docker desktop enable model-runner command to manage Model Runner settings"}} end

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.

Enable Docker Model Runner with a custom TCP port

In the previous step, we enabled the Docker daemon to listen on the default TCP port 2375. In this step, we will learn how to configure the Docker daemon to listen on a custom TCP port instead of the default one. This can be useful for security reasons or to avoid port conflicts.

We will again modify the /etc/docker/daemon.json file. We will change the TCP port from 2375 to a custom port, for example, 2376.

Open the daemon.json file using the nano editor:

sudo nano /etc/docker/daemon.json

Modify the hosts key to change the TCP port from 2375 to 2376. The content of the file should now look like this:

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

Save the file by pressing Ctrl + X, then Y to confirm, and Enter to write to the file name.

After modifying the configuration, you need to restart the Docker service for the changes to take effect.

sudo systemctl restart docker

Now, let's verify that the Docker daemon is listening on the new custom TCP port 2376 and is no longer listening on the default port 2375. We can use the ss command again.

First, check for port 2376:

sudo ss -tuln | grep 2376

You should see output indicating that a process is listening on port 2376:

tcp   LISTEN 0      4096   0.0.0.0:2376      0.0.0.0:*

Next, let's confirm that it is no longer listening on port 2375:

sudo ss -tuln | grep 2375

This command should not produce any output, indicating that the Docker daemon is no longer listening on port 2375.

This confirms that we have successfully configured the Docker daemon to listen on a custom TCP port.

Disable TCP connection for Docker Model Runner

In the previous steps, we enabled the Docker daemon to listen on a default and then a custom TCP port. While enabling TCP can be useful for remote access, it's generally more secure to disable it when not needed and rely on the default Unix socket for local communication.

In this step, we will learn how to disable the TCP connection for the Docker daemon by removing the TCP host entry from the configuration file.

We will again modify the /etc/docker/daemon.json file using the nano editor.

Open the daemon.json file:

sudo nano /etc/docker/daemon.json

Modify the hosts key to remove the TCP entry ("tcp://0.0.0.0:2376" or "tcp://0.0.0.0:2375" depending on the previous step). The content of the file should now only include the Unix socket entry:

{
  "hosts": ["unix:///var/run/docker.sock"]
}

Save the file by pressing Ctrl + X, then Y to confirm, and Enter to write to the file name.

After modifying the configuration, you need to restart the Docker service for the changes to take effect.

sudo systemctl restart docker

Now, let's verify that the Docker daemon is no longer listening on any TCP port. We can use the ss command and check for both port 2375 and 2376.

Check for port 2375:

sudo ss -tuln | grep 2375

This command should not produce any output.

Check for port 2376:

sudo ss -tuln | grep 2376

This command should also not produce any output.

This confirms that we have successfully disabled the TCP connection for the Docker daemon. The daemon is now only accessible via the default Unix socket, which is the more secure default configuration for local access.

Summary

In this lab, we learned how to manage Docker Model Runner settings by enabling and disabling TCP connections for the Docker daemon. We started by enabling the Docker daemon to listen on the default TCP port 2375 by modifying the /etc/docker/daemon.json configuration file to include "tcp://0.0.0.0:2375" in the hosts array and then restarting the Docker service.

The lab also covers how to enable the Docker daemon with a custom TCP port and how to disable TCP connections entirely by removing the TCP entry from the hosts array in the daemon.json file and restarting the Docker service. These steps demonstrate how to configure Docker's network accessibility for different use cases.