Docker MCQs – Docker Networking

11.) Which protocol is primarily used by Docker for container communication?

A) TCP
B) UDP
C) HTTP
D) IP

Answer: Option D

Explanation: Docker primarily uses the IP protocol for communication between containers.

12.) How can you disconnect a container from a network?

A) docker network disconnect <network> <container>
B) docker disconnect <network> <container>
C) docker remove <network>
D) docker detach <network>

Answer: Option A

Explanation: The docker network disconnect command removes a container from a specified network.

13.) What is the default subnet for the bridge network in Docker?

A) 172.17.0.0/16
B) 192.168.0.0/24
C) 10.0.0.0/8
D) 127.0.0.0/8

Answer: Option A

Explanation: The default subnet for the Docker bridge network is 172.17.0.0/16.

14.) Which network driver is required for Docker Swarm to function?

A) Bridge
B) Host
C) None
D) Overlay

Answer: Option D

Explanation: Docker Swarm uses the overlay network driver to enable communication between nodes in the swarm.

15.) What is the purpose of the EXPOSE instruction in a Dockerfile?

A) To map container ports to the host machine
B) To publish ports for the container
C) To specify ports the container listens on
D) To block all ports of the container

Answer: Option C

Explanation: The EXPOSE instruction specifies which ports the container listens on but does not publish them automatically.

16.) Which tool is used to resolve container names to IP addresses in Docker?

A) DNS server
B) Docker DNS
C) Bridge resolver
D) Network manager

Answer: Option B

Explanation: Docker provides a built-in DNS server that resolves container names to their IP addresses.

17.) How do you publish a container port to the host system?

A) Using the -p or –publish flag in docker run
B) Using the –expose flag in docker run
C) Using the –dns flag in docker run
D) By modifying the Dockerfile

Answer: Option A

Explanation: The -p or –publish flag maps container ports to the host system, enabling external access.

18.) What is the purpose of the -P flag in the docker run command?

A) To publish ports explicitly
B) To enable port forwarding
C) To pause the container after running
D) To automatically map container ports to random host ports

Answer: Option D

Explanation: The -P flag automatically maps all exposed container ports to random host ports.

19.) How do you specify a custom subnet when creating a Docker network?

A) docker network create –subnet=<subnet>
B) docker network create –ip-range=<subnet>
C) docker network create –cidr=<subnet>
D) docker network create –mask=<subnet>

Answer: Option A

Explanation: The –subnet option allows you to specify a custom subnet when creating a Docker network.

20.) Which command inspects the IP address of a running container?

A) docker ps
B) docker ip <container>
C) docker network ip
D) docker inspect <container>

Answer: Option D

Explanation: The docker inspect command provides the container’s detailed information, including its IP address.

Leave a Reply

Your email address will not be published. Required fields are marked *