install docker on ubuntu v20 at google cloud platform(GCP)

Hisinhan / Dec 07 2022

12 mins read • 8,000 views

a yellow duck with white background
Goal: Containerised WordPress with docker and host it on GCP. Set up GitHub runner for Continuous integration(CI/CD).

Docker useful commands

docker ps -a
docker images ls
docker volume ls

#remove volumes, images, container
docker rm ${id} --rmi all -v
docker-compose down --rmi all -v

docker-compose start
docker-compose stop

1. Install docker

#ubantu 20 https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt update
sudo apt-cache policy docker-ce
sudo apt install docker-ce

#check status
sudo systemctl status docker
sudo apt-cache policy docker-ce
sudo apt install docker-ce

#check status
sudo systemctl status docker

2. install docker-compose

https://docs.docker.com/compose/install/

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose



3. add Swap space

sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile

sudo swapon /swapfile

#permently setting
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab



4. Install you favourite text editor

5. Set up runner


-ssh to vm
- add new runner, paste command from GitHub runner. Make sure you select Linux OS
- enter runner name

sudo ./svc.sh install 
sudo ./svc.sh start

#
sudo ./svc.sh status


6. Set up SSL

certbot
pass https header to ngnix
extend ssl cert, set cron jbo
configure wp-config

# FTP error

// wp-config.php
define( 'FS_METHOD', 'direct' );

#Wordpress plugin install: Could not create directory

at root folder of WP

sudo chown -R www-data:www-data wp-content/plugins/
sudo chmod 775 wp-content

sudo chown -R www-data:www-data wp-content/