arrow_back

Docker Essentials: Containers and Artifact Registry

로그인 가입
700개 이상의 실습 및 과정 이용하기

Docker Essentials: Containers and Artifact Registry

실습 30분 universal_currency_alt 크레딧 1개 show_chart 입문
info 이 실습에는 학습을 지원하는 AI 도구가 통합되어 있을 수 있습니다.
700개 이상의 실습 및 과정 이용하기

gem-docker-basics

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 hands-on introduction to essential Docker operations, including building, running, managing, and publishing Docker containers. You will learn how to containerize a simple application, interact with the container, and push the resulting image to Google Artifact Registry. This lab assumes familiarity with basic Linux commands and Docker concepts.

Task 1. Setting up your environment and Artifact Registry

In this task, you'll configure your environment, enable the necessary services, and create an Artifact Registry repository to store your Docker images.

  1. Set your Project ID:
gcloud config set project {{{ project_0.project_id | "PROJECT_ID" }}} Note:
This configures the gcloud CLI to use your project.
  1. Enable Artifact Registry API
gcloud services enable artifactregistry.googleapis.com Note:
This command enables the Artifact Registry API for your project, allowing you to create and manage repositories.
  1. Create an Artifact Registry Repository in region:
gcloud artifacts repositories create my-docker-repo \ --repository-format=docker \ --location={{{ project_0.default_region | "REGION" }}} \ --description="My Docker image repository" Note:
Creates a Docker repository in Artifact Registry named `my-docker-repo`.
  1. Configure Docker to authenticate with Artifact Registry:
gcloud auth configure-docker {{{ project_0.default_region | "REGION" }}}-docker.pkg.dev Note:
Authenticates Docker with Artifact Registry for the specified region. This allows you to push and pull images.

Task 2. Building a Docker Image

Here, you will create a simple 'Hello World' application and build a Docker image for it using a Dockerfile.

  1. Create a directory for your application:
mkdir myapp && cd $_ Note:
Creates a new directory named `myapp` and navigates into it.
  1. Create a simple app.py file:
cat > app.py <<EOF from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello, Docker!\n" if __name__ == "__main__": app.run(debug=True, host='0.0.0.0', port=8080) EOF Note:
Creates a simple Flask application that returns 'Hello, Docker!'. This will be our application.
  1. Create a requirements.txt file:
cat > requirements.txt <<EOF Flask EOF Note:
Specifies the dependencies for your application (Flask).
  1. Create a Dockerfile:
FROM python:3.9-slim-buster WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8080 CMD ["python", "app.py"] Note:
Defines the steps to build your Docker image. It uses a Python base image, installs dependencies, copies the application code, and specifies the command to run the application.
  1. Build the Docker image. Replace and
docker build -t {{{ project_0.default_region | "REGION" }}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/my-docker-repo/hello-docker:latest . Note:
Builds the Docker image using the `Dockerfile` in the current directory. It tags the image with the Artifact Registry repository URL.

Task 3. Running and Testing the Docker Container

In this task, you will run the Docker image you built and test it to ensure it's working correctly.

  1. Run the Docker container:
docker run -d -p 8080:8080 {{{ project_0.default_region | "REGION" }}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/my-docker-repo/hello-docker:latest Note:
Runs the Docker image in detached mode (`-d`) and maps port 8080 on the host to port 8080 in the container. You may need to configure firewall rules to allow external traffic on port 8080.
  1. Check if the container is running:
docker ps Note:
Lists the currently running Docker containers.
  1. Test the application. Replace
curl http://localhost:8080 Note:
Sends an HTTP request to the application running in the container. You should see 'Hello, Docker!' in the output.
  1. Stop the Docker container:
docker stop $(docker ps -q) Note:
Stops all running Docker containers. `docker ps -q` returns only the container IDs.

Task 4. Pushing the Image to Artifact Registry

Now that you have a working image, you will push it to your Artifact Registry repository.

  1. Push the Docker image. Replace and
docker push {{{ project_0.default_region | "REGION" }}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/my-docker-repo/hello-docker:latest Note:
Pushes the Docker image to the Artifact Registry repository. This makes the image available for others to use.

Task 5. Cleaning Up

Remove local artifacts to ensure a clean environment.

  1. Remove the application directory:
cd .. && rm -rf myapp Note:
Removes the `myapp` directory and all its contents.

Congratulations!

Congratulations! You have successfully built, run, and pushed a Docker image to Artifact Registry. You learned the basic Docker operations necessary for developing and deploying containerized applications. This lab provides a foundation for more advanced Docker concepts and workflows.

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개만 가능

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

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

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