DCA DCA Docker Networking 1 — Questions and Answers
Question 1: What is the default network driver used when you create a container without specifying a network?
- host
- bridge (Correct answer)
- overlay
- none
Correct answer: bridge
Docker uses the bridge network driver by default when no network is specified at container creation.
Question 2: Which Docker network driver allows containers on different Docker hosts to communicate?
- bridge
- host
- overlay (Correct answer)
- macvlan
Correct answer: overlay
The overlay network driver enables communication between containers across multiple Docker hosts in a Swarm cluster.
Question 3: What command creates a user-defined bridge network named 'my-network'?
- docker network add my-network
- docker network create --driver bridge my-network (Correct answer)
- docker create network my-network
- docker network init my-network
Correct answer: docker network create --driver bridge my-network
The `docker network create --driver bridge my-network` command creates a user-defined bridge network.
Question 4: Which port publishing flag maps host port 8080 to container port 80?
- -p 80:8080
- -P 8080:80
- -p 8080:80 (Correct answer)
- --port 8080-80
Correct answer: -p 8080:80
The `-p 8080:80` flag maps host port 8080 to container port 80 using the host:container format.
Question 5: What does the `--network host` flag do when running a container?
- Creates a new isolated network
- Disables all networking
- Shares the host's network namespace with the container (Correct answer)
- Connects the container to a bridge network
Correct answer: Shares the host's network namespace with the container
The `--network host` flag removes network isolation between the container and the Docker host.
Question 6: Which command displays all Docker networks on a host?
- docker network show
- docker network ls (Correct answer)
- docker network list --all
- docker networks
Correct answer: docker network ls
The `docker network ls` command lists all networks available on the Docker host.
What is the default network driver used when you create a container without specifying a network?