Human-Friendly Guide to Setting Up Docker and Basic Tools on Ubuntu 22.04
In this guide, we will walk you through the process of setting up Docker, MariaDB, Traefik (a load balancer), and creating a volume for your site on an Ubuntu 22.04 server. By following these steps, you will have a solid foundation for running containers and managing your web services efficiently.
Step 1: Access Your Server and Update
Before we begin, log in to your Ubuntu 22.04 server and ensure your system is up-to-date by running the following commands:
$ su - your-username
$ sudo apt update
Step 2: Install Docker
Docker allows you to run containers easily. Install Docker and its prerequisites with the following commands:
$ sudo apt install -y 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 install docker-ce
After installing Docker, add your system user to the Docker group to enable Docker commands without using sudo
:
$ sudo usermod -aG docker $USER
$ newgrp docker
Start Docker and set it to launch at boot:
$ sudo systemctl start docker && sudo systemctl enable docker
Step 3: Installation and Setup
Clone the Repository
To get started with your containerized applications, clone the Frappe Docker repository and navigate to the directory:
$ git clone https://github.com/frappe/frappe_docker
$ cd frappe_docker
Create a Directory for Resources and Configs
Now, create a directory to store your resources and configurations:
$ mkdir ~/gitops
Ensure that OpenSSL is installed on your server:
$ sudo apt install openssl
Install Traefik Ingress
To set up Traefik, you'll need to export some environment variables for your domain and Letsencrypt notification email. Replace your-domain.com
and your-email@example.com
with your domain and email:
$ echo 'TRAEFIK_DOMAIN=your-domain.com' > ~/gitops/traefik.env
$ echo 'EMAIL=your-email@example.com' >> ~/gitops/traefik.env
$ echo 'HASHED_PASSWORD='$(openssl passwd -apr1 YourPassword | sed 's/\$/\\\$/g') >> ~/gitops/traefik.env
Ensure that your DNS entry points to your server's IP address by adding an entry to your hosts file:
$ sudo vim /etc/hosts
Add the following line, replacing 192.168.205.11
with your server's IP and your-domain.com
with your domain:
192.168.205.11 your-domain.com
Once done, you can run a Traefik container using the environment file you created:
$ docker compose --project-name traefik --env-file ~/gitops/traefik.env -f overrides/compose.traefik.yaml up -d
If you have an FQDN and want to run the container with SSL automation (exposing port 443), use the following command:
$ docker compose --project-name traefik --env-file ~/gitops/traefik.env -f overrides/compose.traefik.yaml -f overrides/compose.traefik-ssl.yaml up -d
Step 4: Install MariaDB Container and Create Volumes
To set up MariaDB and create volumes, follow these steps:
Create an Environment File
Create an environment file for MariaDB in the ~/gitops
directory. Replace YourPassword
with your desired password:
$ echo "DB_PASSWORD=YourPassword" > ~/gitops/mariadb.env
Start the MariaDB Container
Start the MariaDB container using Docker Compose:
$ docker compose --project-name mariadb --env-file ~/gitops/mariadb.env -f overrides/compose.mariadb-shared.yaml up -d
Create a Persistent Volume
Create a persistent volume to store your site data:
$ sudo mkdir -p /mnt/data/sites
Set the required permissions:
$ sudo chmod 775 -R /mnt/data
$ sudo chown -R $USER:docker /mnt/data
Now, create the Docker volume for your sites:
$ docker volume create --driver local \
--opt type=none \
--opt device=/mnt/data/sites \
--opt o=bind sites
You have successfully set up Docker, Traefik, MariaDB, and a volume for your site on your Ubuntu 22.04 server. You are now ready to deploy and manage your containerized applications.