π³ Chapter 11: Installing Docker & Deploying Ghost (The Blogging Platform)
Now that your server is live, secured, and fully armed with an SSL certificate... letβs put it to good use! π―
Weβll deploy Ghost β a sleek, fast, and open-source blogging platform. Perfect for personal sites, portfolios, or content projects.
π¦ Step 1: Install Docker & Docker Compose
π§± Update your system and install Docker:
sudo apt update && sudo apt upgrade -y
π€ Optional: Create a Dedicated Docker User
If you donβt want to run everything as root or your main user, you can create a dedicated user for Docker tasks. This improves security and organization, especially in team or production environments π
# Create a new user
sudo adduser dockeruser
# (Optional, usually already exists)
sudo groupadd docker
# Add user to Docker and sudo groups
sudo usermod -aG docker dockeruser
sudo usermod -aG sudo dockeruser
# Confirm group membership
groups dockeruser
π 1.5 β Grant Passwordless Sudo Access
To make Docker and sudo commands smoother (especially in scripts), we can give the user passwordless sudo access:
sudo visudo
Add the following line at the end of the file:
dockeruser ALL=(ALL) NOPASSWD:ALL
Then save and exit:
- Press
Ctrl + O
to save - Press
Enter
to confirm - Press
Ctrl + X
to exit
π 1.6 β Create Volume Directory for Docker (as root)
Letβs now prepare the directory where Docker containers (like Ghost) will store their persistent data.
π€ These commands must be run as root (or with
sudo
)
π Create the volume directory:
mkdir /vw-data
chown dockeruser:docker /vw-data
β
This gives the dockeruser
permission to use the volume in your container setup.
π€ 1.7 β Switch to the dockeruser
and Install Docker
Now that the user and permissions are set up, letβs log in as the Docker user and install the required packages from there β keeping things clean and secure π§Ό
π Switch to the user:
su - dockeruser
π¦ Install Docker & Docker Compose:
sudo apt update && sudo apt upgrade -y
sudo apt install docker.io -y
sudo apt install docker-compose -y
β Check the installation:
docker --version
docker-compose --version
You should see output confirming Docker and Compose versions β meaning itβs ready to go! π³π
π§ Extra: Understanding docker.sock
The file /var/run/docker.sock
is a Unix socket that allows communication between the Docker client and the Docker daemon.
If permissions arenβt correct, you might run into permission denied errors when running Docker as a non-root user.
π Check and fix permissions (run as root):
ls -l /var/run/docker.sock
sudo chown root:docker /var/run/docker.sock
Then make sure Docker is running and enabled:
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl restart docker