This is the steps we will take after we make any new VMs to ensure they are ready to run docker compose and will have a static ip.
Assigning a static IP
We can do this with Netplan. The process goes like this.
First create a backup of the netplan configuration.
sudo cp /etc/netplan/*.yaml /etc/netplan/backup.yaml
Open the configuration with nano
sudo nano /etc/netplan/50-cloud-init.yaml
Replace the configuration with the following, inputting the desired IP
network:
version: 2
ethernets:
ens18:
dhcp4: no
addresses:
- 192.168.4.50/22
# or any other desired address, this is just a template
gateway4: 192.168.4.1
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8
Test it out before applying
sudo netplan try
Try pinging the IP from another VM or LAN device, if it works apply changes with the enter key.
Installing Docker and Docker Compose
Do sudo apt update && sudo apt upgrade first
Install prerequisites
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release
Add Docker’s official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
Add Docker’s official repo
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker + Compose (v2)
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Verify:
docker --version docker compose version
Enable docker without sudo takes effect after logging out and back in
sudo usermod -aG docker bryce
Start docker daemon
sudo systemctl enable --now docker
sudo systemctl status docker --no-pager -l