Creating Debian OS and Installing Docker on GCP Platform


2024-01-28
This article will guide you through the process of creating a Debian operating system on the Google Cloud Platform (GCP) and installing Docker step by step. The process includes setting up a GCP instance and configuring Docker.

Creating Debian OS

After logging into the GCP platform, select on the left menu:

Compute Engine > VM Instances

0

Click the 'Create Instance' button at the top.

0

Fill in the basic instance information and configure the region, machine settings, advanced options, etc., according to your needs and budget.

Pay attention to two main points:

- Choose Debian OS for the boot disk image; if using Ubuntu OS, some commands may differ.

- Make sure to select 'Allow HTTP traffic' and 'Allow HTTPS traffic' in the firewall settings.

0
1

Click 'Create,' wait for the instance creation to complete, then click 'SSH' connection > choose 'Open in browser window' to enter the VM instance.

0

Next, configure local SSH connection keys; this step is optional, as you can also directly use the browser window for SSH connection.

Copy Successful
# Note: For ease of explanation in the following steps, no password is set here. It is recommended to set a password in practice.
# <user-name> is your username.
# <server-name> is your server name.
ssh-keygen -m PEM -t rsa -f ~/.ssh/ssh-key -C <user-name>@<server-name> -b 4096

Copy the ssh-key file to your local machine, and copy the content of the ssh-key.pub file to

Compute Engine > Metadata > SSH Keys

0
1

Now, you can close the browser window connection and use SSH to connect to the GCP VM instance locally.

Open the local terminal and enter the following command to connect to the GCP VM instance:

Copy Successful
# <user-name> is your username.
# <server-ip> is your server IP.
ssh -i ssh-key <user-name>@<server-ip>

Installing Docker

Copy Successful
# Update the apt package repository.
sudo apt-get update
Copy Successful
# Install necessary packages.
sudo apt-get install ca-certificates curl
Copy Successful
# Create the keyring folder and set permissions.
sudo install -m 0755 -d /etc/apt/keyrings
Copy Successful
# Download the public key.
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
Copy Successful
# Set permissions.
sudo chmod a+r /etc/apt/keyrings/docker.asc
Copy Successful
# Set up the repository.
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Copy Successful
# Update the apt package repository.
sudo apt-get update
Copy Successful
# Install Docker.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin