ラボの設定手順と要件
アカウントと進行状況を保護します。このラボを実行するには、常にシークレット ブラウジング ウィンドウとラボの認証情報を使用してください。

Deploy a Static Site with Nginx on Google Cloud Run using Artifact Registry

ラボ 30分 universal_currency_alt クレジット: 1 show_chart 入門
info このラボでは、学習をサポートする AI ツールが組み込まれている場合があります。
このコンテンツはまだモバイル デバイス向けに最適化されていません。
快適にご利用いただくには、メールで送信されたリンクを使用して、デスクトップ パソコンでアクセスしてください。

gem-cloud-run-nginx-website

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

In this lab, you will learn how to deploy a static website using Nginx on Google Cloud Run. You'll build a Docker image, store it in Artifact Registry, and then deploy it to Cloud Run, making your website accessible via a public URL.

Task 1. Set up your Environment

Configure your Google Cloud environment by setting the project ID, region and enabling necessary services.

  1. Set your Project ID is:
gcloud config set project {{{ project_0.project_id | "PROJECT_ID" }}} Note:
This command sets your active project.
  1. Set your default region to
gcloud config set run/region {{{ project_0.default_region | "REGION" }}} Note:
This command sets your default cloud run region.
  1. Enable the Cloud Run and Artifact Registry APIs.
gcloud services enable run.googleapis.com artifactregistry.googleapis.com Note:
This command enables the required Google Cloud services.

Task 2. Create a Static Website

Create a simple HTML file that will be served by Nginx.

  1. Create an index.html file with the following content:
cat > index.html <<EOF <!DOCTYPE html> <html> <head> <title>My Static Website</title> </head> <body> <div>Welcome to My Static Website!</div> <p>This website is served from Google Cloud Run using Nginx and Artifact Registry.</p> </body> </html> EOF Note:
This command creates the index.html file.

Task 3. Create an Nginx Configuration

Create an Nginx configuration file to serve the static website.

  1. Create a nginx.conf file with the following content:
cat > nginx.conf <<EOF events {} http { server { listen 8080; root /usr/share/nginx/html; index index.html index.htm; location / { try_files \$uri \$uri/ =404; } } } EOF Note:
This command creates the nginx.conf file.

Task 4. Create a Dockerfile

Create a Dockerfile to build an image with Nginx and your static website.

  1. Create a Dockerfile with the following content:
cat > Dockerfile <<EOF FROM nginx:latest COPY index.html /usr/share/nginx/html/ COPY nginx.conf /etc/nginx/nginx.conf EXPOSE 8080 CMD ["nginx", "-g", "daemon off;"] EOF Note:
This command creates the Dockerfile.

Task 5. Build and Push the Docker Image to Artifact Registry

Build the Docker image and push it to Artifact Registry.

  1. Create an Artifact Registry repository named nginx-static-site in the region you configured.
gcloud artifacts repositories create nginx-static-site \ --repository-format=docker \ --location={{{ project_0.default_region | "REGION" }}} \ --description="Docker repository for static website" Note:
This command creates the Artifact Registry repository.
  1. Build the Docker image.
docker build -t nginx-static-site . Note:
This command builds the Docker image.
  1. Tag the Docker image with the Artifact Registry repository URL.
docker tag nginx-static-site {{{ project_0.default_region | "REGION" }}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/nginx-static-site/nginx-static-site Note:
This command tags the Docker image.
  1. Push the Docker image to Artifact Registry.
docker push {{{ project_0.default_region | "REGION" }}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/nginx-static-site/nginx-static-site Note:
Ensure Docker is authenticated with gcloud. Run `gcloud auth configure-docker` if you have issues pushing the image.

Task 6. Deploy to Cloud Run

Deploy the Docker image from Artifact Registry to Cloud Run.

  1. Deploy the image to Cloud Run, allowing unauthenticated invocations.
gcloud run deploy nginx-static-site \ --image {{{ project_0.default_region | "REGION" }}}-docker.pkg.dev/{{{ project_0.project_id | "PROJECT_ID" }}}/nginx-static-site/nginx-static-site \ --platform managed \ --region {{{ project_0.default_region | "REGION" }}} \ --allow-unauthenticated Note:
This command deploys the image to Cloud Run and allows unauthenticated access.
  1. Retrieve the Cloud Run service URL.
gcloud run services describe nginx-static-site --platform managed --region {{{ project_0.default_region | "REGION" }}} --format='value(status.url)' Note:
This will print the public URL of your deployed static site.

Task 7. Verify the Deployment

Access the provided URL to verify your deployment. You should see your static website.

  1. Open the URL provided by the gcloud run services describe command in your web browser.
Note:
You should see the 'Welcome to My Static Website!' message.

Congratulations!

Congratulations! You have successfully deployed a static website using Nginx on Google Cloud Run, leveraging Artifact Registry for image storage. You can now customize your website, update the Docker image, and redeploy to Cloud Run to update your site.

Additional Resources

Manual Last Updated Jun 23, 2025

Lab Last Tested Jun 23, 2025

始める前に

  1. ラボでは、Google Cloud プロジェクトとリソースを一定の時間利用します
  2. ラボには時間制限があり、一時停止機能はありません。ラボを終了した場合は、最初からやり直す必要があります。
  3. 画面左上の [ラボを開始] をクリックして開始します

シークレット ブラウジングを使用する

  1. ラボで使用するユーザー名パスワードをコピーします
  2. プライベート モードで [コンソールを開く] をクリックします

コンソールにログインする

    ラボの認証情報を使用して
  1. ログインします。他の認証情報を使用すると、エラーが発生したり、料金が発生したりする可能性があります。
  2. 利用規約に同意し、再設定用のリソースページをスキップします
  3. ラボを終了する場合や最初からやり直す場合を除き、[ラボを終了] はクリックしないでください。クリックすると、作業内容がクリアされ、プロジェクトが削除されます

このコンテンツは現在ご利用いただけません

利用可能になりましたら、メールでお知らせいたします

ありがとうございます。

利用可能になりましたら、メールでご連絡いたします

1 回に 1 つのラボ

既存のラボをすべて終了して、このラボを開始することを確認してください

シークレット ブラウジングを使用してラボを実行する

このラボを実行するには、シークレット モードまたはシークレット ブラウジング ウィンドウを使用することをおすすめします。これにより、個人アカウントと受講者アカウントの競合を防ぎ、個人アカウントに追加料金が発生することを防ぎます。