447 views
4 votes
How to configure docker to use external DNS for all containers that are started on a docker machine?

A) docker run --dns= my-container
B) docker config --dns
C) docker daemon --dns
D) docker network create --dns my-network

2 Answers

2 votes

Final answer:

To configure Docker to use external DNS for all containers started on a Docker machine, the correct option is D) docker network create --dns my-network.

Step-by-step explanation:

Configuring Docker to utilize external DNS for all containers involves creating a Docker network with the desired DNS settings. This ensures that containers connected to this network use the specified DNS configuration.

Using the docker network create command allows you to create a custom network, and by appending the --dns flag followed by the DNS server address, you define the DNS server for that network. This means that any container attached to this network will automatically use the specified external DNS server.

Unlike the other options presented:

Option A (docker run --dns= my-container) is incorrect as it only sets the DNS for a specific container during its runtime, not for all containers.

Option B (docker config --dns) is not a valid command for setting DNS at the network level; it's more related to configuring swarm services.

Option C (docker daemon --dns) is also incorrect, as there is no direct --dns flag for the Docker daemon to set DNS globally for all containers.

In conclusion, the appropriate command for configuring Docker to use external DNS for all containers is D) docker network create --dns my-network.

User MShah
by
7.7k points
4 votes

Final Answer:

The correct option to configure Docker to use external DNS for all containers started on a Docker machine is `docker run --dns= my-container`.

thus correct option is A) docker run --dns= my-container

Step-by-step explanation:

To configure Docker to use an external DNS for all containers on a Docker machine, the appropriate command is `docker run --dns= my-container`. This command allows you to specify the DNS server that Docker should use for name resolution when running a container. By including the `--dns` flag followed by the DNS server address, you ensure that the specified DNS server is used by the containers started with this command.

Using the `docker run` command is essential for configuring DNS on a per-container basis. The `--dns` option provides flexibility in specifying the DNS server, allowing you to connect containers to the desired DNS service. This approach is useful when you want to customize the DNS settings for specific containers, ensuring they can resolve domain names using the specified external DNS server.

Other options mentioned, such as `docker config --dns`, `docker daemon --dns`, and `docker network create --dns my-network`, are not valid for configuring DNS settings for all containers globally. The correct syntax for achieving this goal is the `docker run --dns=` option, making option A the most suitable choice for configuring Docker to use external DNS for containers.

thus correct option is A) docker run --dns= my-container

User LuisEgan
by
7.9k points