DEV Community

ADITYA OKKE SUGIARSO
ADITYA OKKE SUGIARSO

Posted on

Simple docker deploy on gcp

Setup git on gcp
Set up personal SSH keys on Linux
Use Git cmd to manage repo
Install docker so we can use docker compose
Create SSL certificate
GCP IP Address

Setup git on gcp

To install Git on Ubuntu, follow these steps:

Update the package index:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Install Git:

sudo apt install git
Enter fullscreen mode Exit fullscreen mode

Verify the installation:

git --version
Enter fullscreen mode Exit fullscreen mode

You should see the installed Git version.

Set up personal SSH keys on Linux

To clone a repo on bitbucket, you need to set up personal SSH keys

Use Git cmd to manage repo

  • clone the repo using clone command
git clone git@bitbucket.org:{org-name}/{repo-name}.git
Enter fullscreen mode Exit fullscreen mode

above is just sample, you can get the command from clone button in bitbucket repository

  • move to repository folder using cd command
cd {repo-name}
Enter fullscreen mode Exit fullscreen mode
  • use git status to check changes and your current branch
git status
Enter fullscreen mode Exit fullscreen mode
  • change current branch using git checkout
git checkout {branch-name}
Enter fullscreen mode Exit fullscreen mode
  • update your local branch and local commit history according to remote
git fetch
Enter fullscreen mode Exit fullscreen mode
  • pull the changes from remote using git pull
git pull
Enter fullscreen mode Exit fullscreen mode

Install docker so we can use docker compose

full step to install docker on ubuntu are in here

summarize steps:

  • Run the following command to uninstall all conflicting packages:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
Enter fullscreen mode Exit fullscreen mode
  • Set up Docker's apt repository. the step are divided by 2:

First, Add Docker's official GPG key, run these commands:

sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
Enter fullscreen mode Exit fullscreen mode

Second, Add the repository to Apt sources, run these commands:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Install the Docker packages.

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Enter fullscreen mode Exit fullscreen mode

Verify that the Docker Engine installation is successful by running the hello-world image.

docker --version
Enter fullscreen mode Exit fullscreen mode

Create SSL certificate

Step-by-step instructions to install Certbot on linux

Install snapd

sudo apt update
sudo apt install snapd
Enter fullscreen mode Exit fullscreen mode

Update snapd

sudo snap install core
Enter fullscreen mode Exit fullscreen mode

Remove previous Certbot packages

sudo apt-get remove certbot
Enter fullscreen mode Exit fullscreen mode

Install Certbot

sudo snap install --classic certbot
Enter fullscreen mode Exit fullscreen mode

Once certbot is installed, execute the following command to ensure the certbot command can be run:

sudo ln -s /snap/bin/certbot /usr/bin/certbot
Enter fullscreen mode Exit fullscreen mode

Generate SSL Certificate with Let’s Encrypt

sudo certbot certonly --manual --preferred-challenges dns -d *.domain.com -d domain.com
Enter fullscreen mode Exit fullscreen mode

you will get acme value to put on your DNS, in above example, you will get 2 acme that need to put orderly one by one, below are sample DNS TXT acme

Please deploy a DNS TXT record under the name:

_acme-challenge.domain.com.

with the following value:

pdUqtrqSHGKKPv3x2yDyvi0hZhMEUmJtxay82Fhd29f
Enter fullscreen mode Exit fullscreen mode

you need to put value above to your DNS dashboard, my DNS dashboard are look like this

Image description

after you add the record, you can enter on the cmd to continue to the next acme or the next step

Success generated SSL will have this info

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/domain.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/domain.com/privkey.pem
This certificate expires on 2024-12-17.
These files will be updated when the certificate renews.
Enter fullscreen mode Exit fullscreen mode

use both according your approach how to apply SSL on your domain

GCP IP Address

Upgrade your internal and external IP address on GCP to static, so it will not changing when the instance got restart

Image description

register your external address to your dns

Image description

Top comments (0)