How to change dns in docker

How to Change DNS in Docker

Changing DNS (Domain Name System) in Docker can be important for various reasons, such as improving network performance, security, or accessing specific websites or services. In this guide, we will walk you through the steps to change the DNS settings in Docker.

Step 1: Access Docker Configuration

The first step is to access the Docker configuration settings. You can do this by opening a terminal window and running the following command:

sudo nano /etc/docker/daemon.json

This command will open the Docker configuration file in the Nano text editor.

Step 2: Add DNS Configuration

Once you have the Docker configuration file open, you can add the DNS configuration settings. Add the following lines to the configuration file:

{"dns": ["8.8.8.8", "8.8.4.4']}

In this example, we are using Google’s public DNS servers (8.8.8.8 and 8.8.4.4). You can replace these with any DNS server of your choice.

Step 3: Save and Exit the Configuration File

After adding the DNS configuration settings, you need to save and exit the configuration file. To do this, press Ctrl+X, followed by Y to confirm the changes, and then press Enter to save the file.

Step 4: Restart Docker Service

Once you have saved the configuration file, you need to restart the Docker service for the changes to take effect. You can do this by running the following command:

sudo systemctl restart docker

After restarting the Docker service, the new DNS configuration settings will be applied.

Step 5: Verify DNS Configuration

To verify that the DNS configuration changes have been successfully applied, you can run a simple test by running a Docker container and checking if it can resolve domain names using the new DNS settings.

That’s it! You have successfully changed the DNS settings in Docker. By following these steps, you can customize the DNS configuration to suit your specific requirements.

Remember to always test your DNS configuration changes to ensure that they are working as expected.

Comments