| by Arround The Web | No comments

How to Configure Docker Client With a Configuration File?

Docker is a well-established open-source community used to build, deliver and execute software and projects in containers. It works with different components such as Docker images also known as templates of containers, containers small executable packages, Docker engines used to run Docker, Docker server, and client.

The Docker client is a basic component of Docker that is used to interact with Docker. When the users execute any command in Docker, the Docker client interacts with docked or Docker daemon that carries out these commands to the server. The Docker client can be configured using some configuration settings and Docker environment variables in the Docker config file.

In this article, we will illustrate how to configure a Docker client with a configuration file.

How to Configure Docker Client Through Docker Configuration File?

The additional settings and environment variables are set in the configuration file for the Docker client. When the Docker engine starts for the first time, it generates the “config.json” file automatically in the “.docker” directory. But in order to configure additional settings in the Docker client, or to configure the Docker client with a configuration file, follow the listed steps.

Step 1: Launch Text or Code Editor

First, launch the code and text editor from the Start menu. For instance, we will use VS code to create a “config.json” file:


Step 2: Create New File

Next, click on the “New File” to generate the new file. For “Notepad++”, you can use the “CTRL+N” key to create the new file:


Name the file as “config.json” as shown below:


Select the location from the displayed File Manager window and hit the “Create File” button:


Step 3: Add Configuration Settings

Next, add the required configuration settings in JSON format such as storage option, environment variables, or setting proxy. For instance, we have configured the “auths” variable to set the index server URL, enable the experimental feature, set the “log-driver” format as “json-file”, and “storage-driver” as “overlay2”:

{
    "auths": {
      "https://index.docker.io/v1/": {
        "auth": "your_auth_token"
      }
    },
    "experimental": "enabled",
    "log-driver": "json-file",
    "log-level": "debug",
    "storage-driver": "overlay2"
  }

 
After that, press the “CTRL+S” to save changes.

Step 4: Copy the “config.json” File to “.docker” Directory

Next, move the “config.json” file to the “.docker” directory which is usually found in the “C:\users\<user-name>” directory.

To copy the file, first, right-click on the “config.json” file and select the “Copy” option:


Now, navigate to the  “<C:\Users\Dell\.docker>” path and press the “CTRL+V” key to paste the “config.json” file:


Step 5: Restart Docker

After that, click on the highlighted drop-up menu. Then, right-click on the “Docker” icon and press the “Restart” to restart the Docker:


After restarting the Docker, check if the client is configured with a file or not using the “docker info” command:


 

Bonus Tip: How to Configure Docker Client With Configuration File on Linux?

To configure the Docker client on Linux, the same procedure will be followed.

Step 1: Create “config.json” file

First, create the “config.json” file and add the essential configuration into the file to configure the Docker client for Docker:

sudo nano "config.json"

 
Step 2: Move the File in  “</etc/docker/>”

After that, move the file into the “etc/docker/” directory using the “mv” command:

sudo mv config.json /etc/docker/

 
Step 3: Restart Docker

Restart the Docker using the provided command:

sudo systemctl restart docker

 
That’s all about configuring the Docker client with a configuration file.

Conclusion

To configure the Docker client with the “config.json” configuration file, first, create the file named “config.json”. Add the configuration settings such as storage option, environment variables, or setting proxy into the file. Next, for Windows, copy the configuration file into the “<C:\Users\Dell\.docker>” directory. For Linux systems, move the file to the “/etc/docker/” directory. After that, restart the Docker. This article has discussed the method to configure a Docker client for Docker by using a configuration file.

Share Button

Source: linuxhint.com

Leave a Reply