Docker & Kubernetes for Developers · Aula

Configuração de redes de contêineres

Crie e gerencie redes Docker personalizadas para isolar e conectar seus serviços com eficiência.

Aula 2 de 411 etapas

Configuração de redes de contêineres é uma aula grátis de Docker & Kubernetes for Developers no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Docker & Kubernetes for Developers, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Docker & Kubernetes for Developers inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Why Custom Docker Networks?

Docker provides default networks, but for complex applications, custom networks are key. They offer better isolation and controlled communication between your services.

Think of them as private virtual LANs just for your containers, giving you more control over how they interact.

Default Networks: Bridge, Host, None

When you run a container without specifying a network, it usually attaches to the bridge network by default. This allows containers to talk to each other and the host.

  • Bridge: Default, isolated.
  • Host: Container shares host's network stack.
  • None: Isolated, no network access.

While useful, the default bridge network can be limiting for multi-service applications.

Crafting Your Own Network

To create a custom network, you use the docker network create command. The most common type is a bridge network, which acts like a virtual switch.

It provides better isolation and easier service discovery by name for containers connected to it.

docker network create my_app_network

Running Containers on Custom Networks

You can connect a new container to a custom network right when you start it using the --network flag. This is the most common way to get your services talking from the start.

Containers on the same custom bridge network can communicate with each other using their container names as hostnames.

docker run -d --name web_server --network my_app_network nginx:latest

Demo: Web Server on Custom Network

Let's create a custom network and run an Nginx web server on it. We'll publish port 8080 to access it from our host.

First, create the network, then run the container:

docker network create my_web_network
docker run -d --name my_nginx --network my_web_network -p 8080:80 nginx:latest

Connecting Existing Containers

What if you have a container already running and want to connect it to a new custom network? You can use the docker network connect command.

This is useful when you want to dynamically add a container to a network without restarting it.

docker network connect my_app_network existing_container_name

Demo: Add to an Existing Network

Let's say you have a simple Alpine container running. We'll connect it to our previously created my_web_network to allow it to communicate with my_nginx.

First, run a container, then connect it:

docker run -d --name my_alpine alpine sleep 3600
docker network connect my_web_network my_alpine

Peeking into Network Details

To understand what's happening inside your networks, use docker network inspect. This command shows detailed information, including connected containers and their IP addresses.

It's crucial for debugging network issues and verifying connections.

docker network inspect my_web_network

Cleaning Up Your Networks

When containers are no longer needed on a network, you can disconnect them. When a network is no longer in use, it's good practice to remove it to keep your Docker environment tidy.

  • docker network disconnect [network] [container]
  • docker network rm [network_name]

Remember to stop and remove all connected containers before removing a network.

docker network disconnect my_web_network my_alpine
docker network rm my_web_network

Network Configuration Quiz

Let's check your understanding of configuring Docker networks.

Recap: Custom Network Power

In this lesson, you learned how to create and manage custom Docker networks. These networks provide essential isolation and allow your containers to communicate securely by name.

  • Used docker network create to make custom networks.
  • Connected containers with --network or docker network connect.
  • Inspected networks using docker network inspect.
  • Cleaned up with docker network disconnect and docker network rm.

Mastering custom networks is vital for building robust multi-container applications.

Grátis para começar

Aprenda Docker & Kubernetes for Developers com um tutor de IA — grátis

Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.

Cursos
12
Aulas
48

Perguntas Frequentes

A aula “Configuração de redes de contêineres” é grátis?

Sim — o texto completo de “Configuração de redes de contêineres” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Docker & Kubernetes for Developers, atualize para CoddyKit PRO. O curso de Docker & Kubernetes for Developers inclui 4 aulas no total.

O que vou aprender em “Configuração de redes de contêineres”?

Crie e gerencie redes Docker personalizadas para isolar e conectar seus serviços com eficiência. Você pratica Docker & Kubernetes for Developers com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Docker & Kubernetes for Developers?

Nenhuma experiência prévia é necessária. Docker & Kubernetes for Developers no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.

Quanto tempo leva a aula “Configuração de redes de contêineres”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Docker & Kubernetes for Developers?

Sim. Cada aula de Docker & Kubernetes for Developers inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Entendendo os tipos de rede do Docker
  2. Configuração de redes de contêineres
  3. Persistência de dados com volumes
  4. Conectando contêineres com redes do Docker Compose
← Voltar para Docker & Kubernetes for Developers