Comprensión de los tipos de red de Docker
Examine distintos controladores de red de Docker, como bridge, host y overlay, y sus casos de uso para la comunicación entre contenedores.
Comprensión de los tipos de red de Docker es una lección gratuita de Docker & Kubernetes for Developers en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Docker & Kubernetes for Developers, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Docker & Kubernetes for Developers incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
Intro to Docker Networks
Welcome to Docker networking! Containers need to talk to each other and the outside world. Docker networks make this possible.
Understanding network types is key to building robust and scalable applications. Let's dive in!
The Default Bridge Network
When you first install Docker, it creates a default bridge network named bridge. Unless specified, all new containers connect to this network.
- Containers on the same default bridge can communicate via IP address.
- They are isolated from the host machine's network.
Inspecting Default Bridge
You can see the default bridge network and its details using Docker commands. Try running these:
docker network ls
docker network inspect bridgeCustom Bridge Networks
While the default bridge works, custom bridge networks offer significant advantages:
- Isolation: Better segmentation for different applications.
- DNS Resolution: Containers can communicate by name, not just IP.
- Portability: Easier to manage complex setups.
Creating a Custom Bridge Network
Let's create our own custom bridge network. This network will be isolated and provide DNS resolution for containers connected to it.
docker network create my-custom-app-netConnect Containers to Custom Network
Now, let's run two containers on our my-custom-app-net and see them talk to each other using their names. This is a huge benefit!
docker run -d --name web1 --network my-custom-app-net nginx
docker run -it --rm --network my-custom-app-net alpine ping -c 2 web1The 'Host' Network Driver
The host network driver is different. It removes network isolation between the container and the Docker host.
A container using the host network shares the host's network stack directly. This means:
- No port mapping is needed.
- The container uses the host's IP address.
Host Network Use Cases
The host network can be useful for specific scenarios:
- Performance: Minimizes networking overhead.
- Monitoring: Accessing host-level network interfaces directly.
However, it reduces isolation and can lead to port conflicts if not managed carefully.
docker run -it --rm --network host alpine shOverlay Networks for Swarm
When you start dealing with multiple Docker hosts (machines), you need a way for containers on different hosts to communicate. This is where overlay networks come in.
Overlay networks are crucial for Docker Swarm, allowing services to communicate seamlessly across an entire cluster.
Overlay Network Advantages
Overlay networks provide:
- Multi-host communication: Containers on different physical machines can talk.
- Service Discovery: Integrated DNS for services across the swarm.
- Load Balancing: Distributes traffic among service replicas.
They abstract away the underlying physical network complexity.
Network Type Quiz
Test your knowledge of Docker network types!
Network Types Recap
Great job! You've learned about the main Docker network types:
- Bridge (Default & Custom): For single-host container communication. Custom bridges add isolation and DNS.
- Host: For containers that need direct access to the host's network stack.
- Overlay: For multi-host container communication in a Docker Swarm.
Choosing the right network type is vital for your application's architecture. Next, we'll learn how to configure them!
Preguntas frecuentes
¿La lección «Comprensión de los tipos de red de Docker» es gratis?
Sí — el texto completo de «Comprensión de los tipos de red de Docker» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Docker & Kubernetes for Developers, actualiza a CoddyKit PRO. El curso de Docker & Kubernetes for Developers incluye 4 lecciones en total.
¿Qué aprenderé en «Comprensión de los tipos de red de Docker»?
Examine distintos controladores de red de Docker, como bridge, host y overlay, y sus casos de uso para la comunicación entre contenedores. Practicas Docker & Kubernetes for Developers con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Docker & Kubernetes for Developers?
No se requiere experiencia previa. Docker & Kubernetes for Developers en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.
¿Cuánto tiempo toma la lección «Comprensión de los tipos de red de Docker»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Docker & Kubernetes for Developers?
Sí. Cada lección de Docker & Kubernetes for Developers incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Comprensión de los tipos de red de Docker
- Configuración de redes de contenedores
- Persistencia de datos con volúmenes
- Conexión de contenedores con redes de Docker Compose