Arcade Trail: Containers & Load Balancing | GSP055

Solution for Arcade Trail: Containers & Load Balancing | GSP055. 1 lab: GSP055. Fast copy-paste commands for Google Cloud.

GSP055 — Introduction to Docker

Estimated time: 20 minutes

# 🚀 Introduction to Docker | GSP055 > ⚠️ **Disclaimer:** This is an independent, community-made walkthrough created for educational purposes, hands-on practice, and Google Cloud certification preparation. This guide helps learners understand Docker containerization and the process of building and publishing container images using Google Cloud services. Always attempt the lab yourself first and follow Google Cloud Skills Boost / Qwiklabs Terms of Service. This walkthrough is not affiliated with

clear
ORANGE=


\033[38;5;208m'
CYAN=


\033[0;36m'
GREEN=


\033[0;32m'
YELLOW=


\033[0;33m'
MAGENTA=


\033[0;35m'
BLUE=


\033[0;34m'
BOLD=


\033[1m'
RESET=


\033[0m'

echo "${ORANGE}${BOLD}   ____        _   _ _            __   ___              ${RESET}"
echo "${ORANGE}${BOLD}  / __ \      | | (_) |          / _| / _ \             ${RESET}"
echo "${ORANGE}${BOLD} | |  | |_ __| |__  _| |_  ___   | |_ | | | |_ __ ___  ${RESET}"
echo "${ORANGE}${BOLD} | |  | | '__| '_ \| | __| / _ \ |  _|| | | | '_ \ / __| ${RESET}"
echo "${ORANGE}${BOLD} | |__| | |  | |_) | | |_ | (_) || |  | |_| | |_) \__ \ ${RESET}"
echo "${ORANGE}${BOLD}  \____/|_|  |_.__/|_|\__| \___/ |_|   \___/| .__/|___/ ${RESET}"
echo "${ORANGE}${BOLD}                                            | |         ${RESET}"
echo "${ORANGE}${BOLD}                                            |_|         ${RESET}"
echo ""
echo "${MAGENTA}${BOLD}==========================================================${RESET}"
echo "${MAGENTA}${BOLD} STAGE 1: Initialization                                  ${RESET}"
echo "${MAGENTA}${BOLD}==========================================================${RESET}"

read -p "${BLUE}${BOLD}Enter your assigned REGION (e.g., us-central1): ${RESET}" REGION
export REGION=$REGION
export PROJECT_ID=$(gcloud config get-value project)

echo "${GREEN}${BOLD}✓ Environment configured. Proceed to Command 2.${RESET}"
ORANGE=


\033[38;5;208m'
CYAN=


\033[0;36m'
GREEN=


\033[0;32m'
YELLOW=


\033[0;33m'
MAGENTA=


\033[0;35m'
BLUE=


\033[0;34m'
BOLD=


\033[1m'
RESET=


\033[0m'

echo "${MAGENTA}${BOLD}==========================================================${RESET}"
echo "${MAGENTA}${BOLD} STAGE 2: Build Node.js Application                       ${RESET}"
echo "${MAGENTA}${BOLD}==========================================================${RESET}"

echo "${YELLOW}▶ Creating application files...${RESET}"
mkdir -p test && cd test

cat << 'EOF' > Dockerfile
FROM node:lts
WORKDIR /app
ADD . /app
EXPOSE 80
CMD ["node", "app.js"]
EOF

cat << 'EOF' > app.js
const http = require("http");
const hostname = "0.0.0.0";
const port = 80;
const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader("Content-Type", "text/plain");
  res.end("Welcome to Cloud\n");
});
server.listen(port, hostname, () => {
  console.log("Server running at http://%s:%s/", hostname, port);
});
process.on("SIGINT", function () {
  console.log("Caught interrupt signal and will exit");
  process.exit();
});
EOF

echo "${YELLOW}▶ Building Docker Image (This may take a minute)...${RESET}"
docker build -t node-app:0.2 .

echo "${GREEN}${BOLD}✓ Local Docker image built successfully. Proceed to Command 3.${RESET}"
ORANGE=


\033[38;5;208m'
CYAN=


\033[0;36m'
GREEN=


\033[0;32m'
YELLOW=


\033[0;33m'
MAGENTA=


\033[0;35m'
BLUE=


\033[0;34m'
BOLD=


\033[1m'
RESET=


\033[0m'

echo "${MAGENTA}${BOLD}==========================================================${RESET}"
echo "${MAGENTA}${BOLD} STAGE 3: Publish to Artifact Registry                    ${RESET}"
echo "${MAGENTA}${BOLD}==========================================================${RESET}"

echo "${YELLOW}▶ Creating Artifact Registry Repository...${RESET}"
gcloud artifacts repositories create my-repository --repository-format=docker --location=$REGION --description="Docker repository" --quiet

echo "${YELLOW}▶ Configuring Docker Authentication...${RESET}"
gcloud auth configure-docker $REGION-docker.pkg.dev --quiet

echo "${YELLOW}▶ Tagging and Pushing Image to Artifact Registry...${RESET}"
docker tag node-app:0.2 $REGION-docker.pkg.dev/$PROJECT_ID/my-repository/node-app:0.2
docker push $REGION-docker.pkg.dev/$PROJECT_ID/my-repository/node-app:0.2

echo "${YELLOW}▶ Cleaning up local environment and deploying from Registry...${RESET}"
docker stop $(docker ps -q) 2>/dev/null || true
docker rm $(docker ps -aq) 2>/dev/null || true
docker run -p 4000:80 -d $REGION-docker.pkg.dev/$PROJECT_ID/my-repository/node-app:0.2

echo "${GREEN}${BOLD}✓ Container published successfully!${RESET}"
echo "${ORANGE}${BOLD}You may now click 'Check my progress' in your lab manual.${RESET}"
echo "${MAGENTA}${BOLD}==========================================================${RESET}"