In this post, I will share a few notes which I prepared for the DCA exam. These notes are not complete to cover Docker Networking. But you can use these as reference for quick revision
Host Networking:
1) Container does not get its own IP-address allocated. If you run a container that binds to port 80 and you use host networking, the container’s application is available on port 80 on the host’s IP address.
2) Host mode networking can be useful to optimize performance.
3) The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server
4) You can also use a host network for a swarm service, by passing --network host to the docker service create command.
Bridge Network:
Bridge network is a Link Layer device that forwards traffic between network segments. Advantage of user-defined bridge network:
1) User-defined bridges provide better isolation.: Related containers can communicate with each other bypassing --network command while creating service.
2) During a container’s lifetime, you can connect or disconnect it from user-defined networks on the fly. To remove a container from the default bridge network, you need to stop the container and recreate it with different network options.
4) Each user-defined network creates a configurable bridge.
Overlay networks connect multiple Docker daemons together and enable swarm services to communicate with each other
You can also use overlay networks to facilitate communication between a swarm service and a standalone container, or between two standalone containers on different Docker daemons.
TCP port 2377 for cluster management communications
TCP and UDP port 7946 for communication among nodes
UDP port 4789 for overlay network traffic
none: For this container, disable all networking. Usually used in conjunction with a custom network driver.none is not available for swarm services.
Macvlan networks:
1) Macvlan networks are best when you are migrating from a VM setup or need your containers to look like physical hosts on your network, each with a unique MAC address.
2) The macvlan driver is the newest built-in network driver and offers several unique characteristics. It’s a very lightweight driver because rather than using any Linux bridging or port mapping, it connects container interfaces directly to host interfaces.
3) Scope of Macvlan network is local.
Faqs:
1) When the container starts, it can only be connected to a single network, using --network. However, you can connect a running container to multiple networks using docker network connect
2) You can override the hostname using --hostname
Create Service with Custom Overlay Network:
docker service create --name myoverlay --network mynetwork --replicas 3 nginx
Verify Networks:
docker network ls
Find the IP of Container docker container inspect [CONTAINER-NAME]
Connect to Container and Install Ping
docker container exec -it [CONTAINER-NAME]
apt-get update && apt-get install iputils-ping ping [IP]
Securing Overlay Network:
docker network create --opt encrypted --driver overlay
.jpg)