Installation Docker & Docker-compose
- Installation de Docker en ligne de commande
- Redirection flux conteneur avec Apache
- Installation de docker-compose
Installation de Docker en ligne de commande
Le paquet d'installation de Docker disponible dans le dépôt officiel de Debian peut ne pas être la dernière version. Pour s'assurer d'obtenir la dernière version, nous allons installer Docker à partir du dépôt officiel de Docker. Pour cela, nous allons ajouter une nouvelle source de paquet, ajouter la clé GPG de Docker pour s'assurer que les téléchargements sont valides, puis installer le paquet.
Installer quelques paquets prérequis qui permettent à apt d'utiliser des paquets sur HTTPS :
sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common
Ajoutez ensuite la clé GPG du dépôt officiel de Docker à votre système :
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
Ajouter le dépôt Docker aux sources APT :
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
Ensuite, mettez à jour la base de données de paquets avec les paquets Docker du nouveau repo :
sudo apt update
Make sure you are about to install from the Docker repo instead of the default Debian repo:
apt-cache policy docker-ce
You’ll see output like this, although the version number for Docker may be different:
docker-ce:
Installed: (none)
Candidate: 5:20.10.12~3-0~debian-buster
Version table:
5:20.10.12~3-0~debian-buster 500
500 https://download.docker.com/linux/debian buster/stable amd64 Packages
Notice that docker-ce is not installed, but the candidate for installation is from the Docker repository for Debian 10 (buster).
Finally, install Docker:
sudo apt install docker-ce
Docker is now installed, the daemon started, and the process enabled to start on boot. Check that it’s running:
sudo systemctl status docker
The output will be similar to the following, showing that the service is active and running:
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-07-08 15:11:19 UTC; 58s ago
Docs: https://docs.docker.com
Main PID: 5709 (dockerd)
Tasks: 8
Memory: 31.6M
CGroup: /system.slice/docker.service
└─5709 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Installing Docker gives you not just the Docker service (daemon) but also the docker command line utility, or the Docker client. We’ll explore how to use the docker command later in this tutorial.
Redirection flux conteneur avec Apache
Pour rendre accessible un conteneur via un nom de domaine il faut réaliser une configuration vhost Apache un peu particulière.
Par exemple, pour rediriger tout le trafic provenant de l'url container.domaine.com vers le conteneur mycontainer1 écoutant sur le port 3000, il faut faire la configuration suivante :
<VirtualHost *:80>
ServerName container.domaine.com
ErrorLog ${APACHE_LOG_DIR}/container.domaine.com.log
CustomLog ${APACHE_LOG_DIR}/container.domaine.com.log combined
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
Cependant cette configuration vhost demande l'activation de plusieurs module qui ne sont pas activés par défaut dans Apache.
Installation de docker-compose
Update the package index, and install the latest version of Docker Compose:
-
For Ubuntu and Debian, run:
$ sudo apt-get update $ sudo apt-get install docker-compose-plugin