실습 설정 안내 및 요구사항
계정과 진행 상황을 보호하세요. 이 실습을 실행하려면 항상 시크릿 브라우저 창과 실습 사용자 인증 정보를 사용하세요.

Docker Essentials: Container Networking

실습 30분 universal_currency_alt 크레딧 1개 show_chart 입문
info 이 실습에는 학습을 지원하는 AI 도구가 통합되어 있을 수 있습니다.
이 콘텐츠는 아직 휴대기기에 최적화되지 않음
최상의 경험을 위해 데스크톱 컴퓨터에서 이메일로 전송된 링크를 사용하여 방문하세요.

gem-docker-networking

Google Cloud self-paced labs logo

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. The output contains a line that declares the PROJECT_ID for this session:

Your Cloud Platform project in this session is set to YOUR_PROJECT_ID

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

  2. Your output should now look like this:

Output:

ACTIVE: * ACCOUNT: student-01-xxxxxxxxxxxx@qwiklabs.net To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = <project_ID>

Example output:

[core] project = qwiklabs-gcp-44776a13dea667a6 Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Overview

This lab provides a practical exploration of Docker networking. You will learn how containers communicate with each other and the outside world using various networking modes. You'll also learn how to create custom networks and control container communication. We will use Artifact Registry to host the container images used in this lab.

Task 1. Setting up the Environment

In this task, you will configure your environment and pull the necessary images from Artifact Registry.

  1. Set your Project ID is:
gcloud config set project {{{ project_0.project_id | "PROJECT_ID" }}} Note:
This command sets your active project identity.
  1. Set your default region to
gcloud config set compute/region {{{ project_0.default_region | "REGION" }}} Note:
This command sets your active compute region.
  1. Enable the Artifact Registry API.
gcloud services enable artifactregistry.googleapis.com Note:
Enables the Artifact Registry service.
  1. Create a Docker repository in Artifact Registry. Replace lab-registry with a name for your repository. It must be unique within the specified region.
gcloud artifacts repositories create lab-registry --repository-format=docker --location={{{ project_0.default_region | "REGION"}}} --description="Docker repository" Note:
Creates a Docker repository in Artifact Registry.
  1. Configure Docker to authenticate with Artifact Registry.
gcloud auth configure-docker {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev Note:
This command configures Docker to use your Google Cloud credentials for authentication with Artifact Registry.
  1. Pull the alpine/curl image from Docker Hub and tag it for your Artifact Registry.
docker pull alpine/curl && docker tag alpine/curl {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/alpine-curl:latest Note:
This will pull the image from docker hub and tag it for Artifact Registry.
  1. Push the alpine/curl image to Artifact Registry.
docker push {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/alpine-curl:latest strong>Note:
This command pushes the tagged image to your Artifact Registry repository.
  1. Pull the nginx:latest image from Docker Hub and tag it for your Artifact Registry.
docker pull nginx:latest && docker tag nginx:latest {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/nginx:latest Note:
This will pull the image from docker hub and tag it for Artifact Registry.
  1. Push the nginx:latest image to Artifact Registry.
docker push {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/nginx:latest Note:
This command pushes the tagged image to your Artifact Registry repository.

Task 2. Exploring Default Bridge Network

This task explores the default bridge network Docker creates. You will run containers and observe their communication within this network.

  1. Run container1 using the alpine/curl image.
docker run -d --name container1 {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/alpine-curl:latest sleep infinity
  1. Run container2 using the alpine/curl image.
docker run -d --name container2 {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/alpine-curl:latest sleep infinity Note:
This starts two containers in detached mode. The `sleep infinity` command keeps the containers running.
  1. Inspect the default bridge network.
docker network inspect bridge Note:
This shows details of the `bridge` network, including connected containers and IP addresses.
  1. From container1, ping container2 using its name. Note that Docker uses embedded DNS for name resolution within the default bridge network.
docker exec -it container1 ping container2 Note:
This executes the `ping` command within `container1`, targeting `container2`. The standard bridge network does not provide DNS resolution, so ping command cannot use the container name.
  1. Stop container2 from runnning.
docker stop container2 && docker rm container2
  1. Restart container2 running as an HTTP server.
docker run -d --name container2 -p 8080:80 {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/nginx:latest Note:
Start a new container2 running nginx and exposing port 8080.
  1. From container1, use curl to make an HTTP request to container2.
docker exec -it container1 curl container2:8080 Note:
Send a curl request from container1 to container2 on port 8080. The standard bridge network does not provide DNS resolution, so curl command cannot use the container name.

Task 3. Creating and Using Custom Networks

This task demonstrates how to create a custom network which supports DNS and connect containers to it, providing more control over network configuration.

  1. Create a new network named my-net.
docker network create my-net Note:
Creates a new Docker network named `my-net`.
  1. Run container 3 connecting it to the my-net network.
docker run -d --name container3 --network my-net {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/alpine-curl:latest sleep infinity
  1. Run container 4 connecting it to the my-net network.
docker run -d --name container4 --network my-net {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/alpine-curl:latest sleep infinity Note:
Starts two containers connected to the `my-net` network.
  1. Inspect the my-net network to see the connected containers and their IP addresses.
docker network inspect my-net Note:
Displays details about the `my-net` network.
  1. From container3, ping container4 using its name. Name resolution works within custom networks as well.
docker exec -it container3 ping container4 Note:
Tests connectivity between containers within `my-net`.
  1. Stop the active container 4 from running.
docker stop container4 && docker rm container4
  1. Restart container 4.
docker run -d --name container4 --network my-net -p 8081:80 {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/nginx:latest
  1. Run an nginx container on my-net and test connectivity.
docker exec -it container3 curl container4:80 Note:
Starts an nginx container on my-net.
  1. Stop the active container 4 from running.
docker stop container4 && docker rm container4

Task 4. Publishing Ports and Accessing Containers from the Host

Learn how to publish container ports and access containerized services from the host machine.

  1. Run an nginx container, publishing port 80 to the host's port 8080.
docker run -d --name container4 -p 8080:80 {{{ project_0.default_region | "REGION"}}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/lab-registry/nginx:latest Note:
Publishes port 80 of the container to port 8080 on the host.
  1. Access the nginx service from the host machine using curl.
curl localhost:8080 Note:
This command sends an HTTP request to the published port on the host machine.
  1. Use docker port to check the port mapping.
docker port container4 80 Note:
This command shows the mapping for port 80 of the container.

Task 5. Cleaning Up

Remove the created containers and networks.

  1. Stop all containers.
docker stop container1 container2 container3 container4
  1. Remove all containers.
docker rm container1 container2 container3 container4 Note:
This stops and removes the containers created in the previous steps.
  1. Remove the my-net network.
docker network rm my-net Note:
This removes the custom network.

Congratulations!

You've successfully explored Docker networking, including the default bridge network, custom networks, and port publishing. You now understand how containers communicate with each other and the outside world. Further explore Docker Compose for multi-container applications and overlay networks for multi-host networking.

Additional Resources

Manual Last Updated Jun 24, 2025

Lab Last Tested Jun 24, 2025

시작하기 전에

  1. 실습에서는 정해진 기간 동안 Google Cloud 프로젝트와 리소스를 만듭니다.
  2. 실습에는 시간 제한이 있으며 일시중지 기능이 없습니다. 실습을 종료하면 처음부터 다시 시작해야 합니다.
  3. 화면 왼쪽 상단에서 실습 시작을 클릭하여 시작합니다.

시크릿 브라우징 사용

  1. 실습에 입력한 사용자 이름비밀번호를 복사합니다.
  2. 비공개 모드에서 콘솔 열기를 클릭합니다.

콘솔에 로그인

    실습 사용자 인증 정보를 사용하여
  1. 로그인합니다. 다른 사용자 인증 정보를 사용하면 오류가 발생하거나 요금이 부과될 수 있습니다.
  2. 약관에 동의하고 리소스 복구 페이지를 건너뜁니다.
  3. 실습을 완료했거나 다시 시작하려고 하는 경우가 아니면 실습 종료를 클릭하지 마세요. 이 버튼을 클릭하면 작업 내용이 지워지고 프로젝트가 삭제됩니다.

현재 이 콘텐츠를 이용할 수 없습니다

이용할 수 있게 되면 이메일로 알려드리겠습니다.

감사합니다

이용할 수 있게 되면 이메일로 알려드리겠습니다.

한 번에 실습 1개만 가능

모든 기존 실습을 종료하고 이 실습을 시작할지 확인하세요.

시크릿 브라우징을 사용하여 실습 실행하기

이 실습을 실행하는 가장 좋은 방법은 시크릿 모드 또는 시크릿 브라우저 창을 사용하는 것입니다. 개인 계정과 학생 계정 간의 충돌로 개인 계정에 추가 요금이 발생하는 일을 방지해 줍니다.