Cloud & containers

Installing Docker and Docker-compose

Install Docker and Docker-compose on a server step by step, then create a docker-compose file to deploy your first containers, such as a WireGuard server.

· 2 min read · level: intermediate · on docker-compose 1.29.1

We are going to see together how to install Docker easily. I will guide you step by step through the installation and the creation of a docker-compose.yml file

Before we can create and start containers, we need to install Docker and Docker-compose in order to create configuration files. If you have already installed docker and docker-compose on your server, you can skip these steps.

Illustration 1 — Installation de Docker et Docker-compose

Installing Docker

curl -fsSL https://get.docker.com/ | sh

Adding a user to the docker group in order to run the docker command

sudo usermod -aG docker username

Installing docker-compose

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

Adding execution rights on docker-compose

sudo chmod +x /usr/local/bin/docker-compose

Creating a docker-compose file

Next, we need to create a docker-compose file in order to manage the deployment of our dockers easily. To do this, I often use docker images and templates from the website https://linuxserver.io. The people at linuxserver.io are enthusiasts and maintain many images for the docker community.

First of all, we are going to create a new folder in the /opt directory called /opt/wireguard-server and create a new docker-compose.yaml file in this directory. You must also change the ownership of this folder to your Linux user.

sudo mkdir /opt/docker
nano /opt/docker/docker-compose.yaml

Start your WireGuard server

You can now start your WireGuard container with the following command and clients should be able to connect.

cd /opt/wireguard-server
docker-compose up -d

We will meet again soon for the deployment of applications on Docker with, for example, Wordpress, WireGuard, Nextcloud or Vaultwarden.