Konfigurowanie sieci kontenerów
Utwórz niestandardowe sieci Docker i zarządzaj nimi, aby skutecznie izolować i łączyć usługi.
Konfigurowanie sieci kontenerów to bezpłatna lekcja Docker & Kubernetes for Developers na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Docker & Kubernetes for Developers, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Docker & Kubernetes for Developers zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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_networkRunning 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:latestDemo: 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:latestConnecting 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_nameDemo: 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_alpinePeeking 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_networkCleaning 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_networkNetwork 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 createto make custom networks. - Connected containers with
--networkordocker network connect. - Inspected networks using
docker network inspect. - Cleaned up with
docker network disconnectanddocker network rm.
Mastering custom networks is vital for building robust multi-container applications.
Ucz się Docker & Kubernetes for Developers dzięki korepetycjom AI — za darmo
Pisz i uruchamiaj kod w przeglądarce, otrzymuj natychmiastową pomoc od korepetytora AI dostępnego 24/7 i kontynuuj naukę w sieci lub w aplikacji.
- Kursy
- 12
- Lekcje
- 48
Często zadawane pytania
Czy lekcja „Konfigurowanie sieci kontenerów” jest bezpłatna?
Tak — pełny tekst „Konfigurowanie sieci kontenerów” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Docker & Kubernetes for Developers, przejdź na CoddyKit PRO. Kurs Docker & Kubernetes for Developers zawiera 4 lekcji w sumie.
Co nauczysz się w „Konfigurowanie sieci kontenerów”?
Utwórz niestandardowe sieci Docker i zarządzaj nimi, aby skutecznie izolować i łączyć usługi. Ćwiczysz Docker & Kubernetes for Developers z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Docker & Kubernetes for Developers?
Nie wymagamy żadnego doświadczenia. Docker & Kubernetes for Developers w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.
Ile czasu zajmuje lekcja „Konfigurowanie sieci kontenerów”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Docker & Kubernetes for Developers?
Tak. Każda lekcja Docker & Kubernetes for Developers zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Poznawanie typów sieci Docker
- Konfigurowanie sieci kontenerów
- Trwałość danych dzięki wolumenom
- Łączenie kontenerów za pomocą sieci Docker Compose