07/03/2018

Docker

Installation

Debian

apt update && apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
apt update && apt install docker-ce docker-ce-cli containerd.io

Ubuntu

sudo apt install apt-transport-https ca-certificates curl gnupg-agent 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 $(lsb_release -cs) stable"
sudo apt install docker-ce docker-ce-cli containerd.io

Pour installer docker dans un conteneur lxc sur une machine hote avec un apparmor (ex: debian 10), rajoutez cette ligne au fichier de config di conteneur) :

lxc.apparmor.profile = unconfined

Docker compose :

sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

Si vous voulez utiliser docker avec votre utilisateur (autre que root) il faut l’ajouter au groupe docker

usermod -aG docker [your-user] 

Utilisation

Créer un container

Exemple nginx (sur le dockerHub)

docker run -d -p 8080:80 nginx

Recuperer une image docker

docker pull [name]

Administrer les process

Afficher les dockers en cours

docker ps

Stoper un docker

docker stop [id]

Lancer une invite de commande

docker exec -it [id] /bin/bash

Sur lxc

Pour installer docker sur lxc il faut rajouter quelques options sur le fichier de config sinon vous tomberez sur cette erreur :

docker: failed to register layer: ApplyLayer exit status 1 stdout: stderr: remount /,

lxc.apparmor.profile = unconfined

lxc.cgroup.devices.allow = c 10:200 rwm

Exemple DockerFile

FROM nginx:alpine
COPY webapp/ /usr/share/nginx/html/
CMD  ["nginx-debug", "-g", "daemon off;"]
VOLUME ["/usr/share/nginx/html"]
EXPOSE 80

Lancer :

docker build .

docker run -d -p 80:80 testu