Outils pour utilisateurs

Outils du site


informatique:docker

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
informatique:docker [07/05/2016 09:07] – [Multi Process Docker Images] cyrilleinformatique:docker [24/11/2023 20:44] (Version actuelle) – [Copier une image] cyrille
Ligne 38: Ligne 38:
   * [[https://docs.docker.com/engine/userguide/|Docker Engine user guide]]   * [[https://docs.docker.com/engine/userguide/|Docker Engine user guide]]
     * [[https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/|Best practices for writing Dockerfiles]]     * [[https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/|Best practices for writing Dockerfiles]]
 +
 +[[https://blog.imirhil.fr/2016/10/09/docker-container-hell.html|Docker et la tendance de la conteneurisation : a-t-elle vraiment été en production ?]] 2016-10-09
  
 Cheat sheets: Cheat sheets:
Ligne 51: Ligne 53:
   * [[https://dockerbook.com/|The Docker Book]] by James Turnbull - 10$ epub/pdf   * [[https://dockerbook.com/|The Docker Book]] by James Turnbull - 10$ epub/pdf
 ==== Installation ==== ==== Installation ====
 +
 +  * Ubuntu: https://docs.docker.com/engine/installation/linux/ubuntulinux/
 +  * Debian: https://docs.docker.com/engine/installation/linux/debian/
  
 <code bash> <code bash>
Ligne 83: Ligne 88:
 </code> </code>
  
 +if you are running short-term foreground processes, add ''--rm'' option.
 +
 +Voir [[https://docs.docker.com/engine/reference/run/|reference/run]]
 +=== docker start ===
 +
 +Relancer un container arrếté (exited)
 +<code bash>
 +  docker start -i <ID>
 +</code>
 === docker ps === === docker ps ===
  
Ligne 125: Ligne 139:
   --no-trunc           Don't truncate output   --no-trunc           Don't truncate output
   -q, --quiet          Only show numeric IDs   -q, --quiet          Only show numeric IDs
 +</code>
 +
 +=== docker commit ===
 +
 +[[https://docs.docker.com/engine/reference/commandline/commit/|commit reference]]
 +
 +=== docker save ===
 +
 +<code bash>
 + docker save -o <save image filename> <image name>
 +</code>
 +ou
 +<code bash>
 + docker save <image name> | bzip2 > -o <save image filename.bz2>
 +</code>
 +
 +=== docker cp ===
 +
 +Pour copier un fichier du container vers le host;
 +<code bash>
 +docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH
 +</code>
 +
 +=== docker volume rm ===
 +
 +<code bash>
 +docker volume rm [OPTIONS] VOLUME [VOLUME...]
 </code> </code>
 ==== Dockerfile ==== ==== Dockerfile ====
Ligne 144: Ligne 185:
 https://github.com/docker/swarm/ https://github.com/docker/swarm/
  
-==== Compose ====+==== Compose (docker-composer) ====
  
 Docker Compose permet de créer et configurer un ensemble de conteneurs avec un fichier YAML. Docker Compose permet de créer et configurer un ensemble de conteneurs avec un fichier YAML.
Ligne 161: Ligne 202:
 $ machine create -d [infrastructure provider] [provider options] [machine name] $ machine create -d [infrastructure provider] [provider options] [machine name]
 </code> </code>
 +
 +==== Docker Desktop ====
 +
 +https://docs.docker.com/desktop/
 +==== Rancher ====
 +
 +[[http://rancher.com/rancher/|Rancher]] natively supports and manages all of your Kubernetes, Mesos, and Swarm clusters.
  
 ===== Images Docker ===== ===== Images Docker =====
  
-==== nginx-proxy ====+==== nginx-proxy & acme-companion ====
  
-https://hub.docker.com/r/jwilder/nginx-proxy/+  * https://github.com/nginx-proxy/nginx-proxy <del>https://github.com/jwilder/nginx-proxy</del>  
 +  * https://github.com/nginx-proxy/acme-companion
  
-Le container [[https://hub.docker.com/r/jwilder/nginx-proxy/|jwilder/nginx-proxy]] sert de reverse proxy aux containers Dockers fournissant des services web.+C'est le reverse proxy pour d'autres containers fournissant des services web. Accompagné de ''acme-companion'' on obtient le HTTPS LetsEncrypt automatique. 
 + 
 +acme-companion is a lightweight companion container for nginx-proxy. It handles the automated creation, renewal and use of LetsEncrypt SSL certificates for proxied Docker containers through the ACME protocol. 
 + 
 +  * Automated creation/renewal of Let's Encrypt (or other ACME CAs) certificates using acme.sh. 
 +  * Let's Encrypt / ACME domain validation through http-01 challenge only. 
 +  * Automated update and reload of nginx config on certificate creation/renewal. 
 +  * Support creation of Multi-Domain (SAN) Certificates. 
 +  * Creation of a Strong Diffie-Hellman Group at startup. 
 +  * Work with all versions of docker. 
 + 
 +{{ https://raw.githubusercontent.com/nginx-proxy/acme-companion/main/schema.png?460 }} 
 + 
 +Les 2 dans un docker-compose et le tour est joué: 
 +<code yaml> 
 +volumes: 
 +  conf: 
 +  vhost: 
 +  html: 
 +  dhparam: 
 +  certs: 
 +  acme: 
 + 
 +services: 
 +  nginx-proxy
 +    image: nginxproxy/nginx-proxy 
 +    container_name: nginx-proxy 
 +    ports: 
 +      - "80:80" 
 +      - "443:443" 
 +    volumes: 
 +      - conf:/etc/nginx/conf.d 
 +      - vhost:/etc/nginx/vhost.d 
 +      - html:/usr/share/nginx/html 
 +      - dhparam:/etc/nginx/dhparam 
 +      - certs:/etc/nginx/certs:ro 
 +      - /var/run/docker.sock:/tmp/docker.sock:ro 
 +    network_mode: bridge 
 +  acme-companion: 
 +    image: nginxproxy/acme-companion 
 +    container_name: nginx-proxy-acme 
 +    volumes_from: 
 +      - nginx-proxy 
 +    volumes: 
 +      - certs:/etc/nginx/certs:rw 
 +      - acme:/etc/acme.sh 
 +      - /var/run/docker.sock:/var/run/docker.sock:ro 
 +    network_mode: bridge 
 +</code> 
 + 
 +Il suffit ensuite de lancer des containers avec les ENV qui vont bien: 
 +<code bash> 
 +docker run -d -p 8000:8000 --name dokuwiki -v $(pwd)/data:/data \ 
 + --env "VIRTUAL_HOST=backup-01.comptoir.net"
 + --env "VIRTUAL_PORT=8000"
 + --env "LETSENCRYPT_HOST=toto.comptoir.net"
 + --env "LETSENCRYPT_EMAIL=toto@comptoir.net"
 + crazymax/dokuwiki:latest 
 +</code> 
 + 
 +Et voilà le container ''dokuwiki'' est automatiquement prit en charge par ''nginx-proxy'' et sont certificat https généré par ''acme-companion'' :-) 
 + 
 +<WRAP center round important 60%> 
 +Il reste un mauvais point: le container ''dokuwiki'' est accessible (LISTEN) sur le ''host'', il faut donc activer et configurer un firewall.\\ J'ai essayé avec des ''network'' mais ne suis pas arrivé à isoler les container vhosts. 
 +</WRAP> 
 + 
 +On le voit sur le port ''32771''
 +<code> 
 +# netstat -tanp | grep LISTEN 
 +tcp        0      0 0.0.0.0:30001           0.0.0.0:              LISTEN      670/sshd             
 +tcp        0      0 127.0.0.1:25            0.0.0.0:              LISTEN      937/exim4            
 +tcp6            0 :::32771                :::*                    LISTEN      22408/docker-proxy   
 +tcp6            0 :::80                   :::                   LISTEN      21823/docker-proxy   
 +tcp6            0 :::30001                :::*                    LISTEN      670/sshd             
 +tcp6            0 ::1:25                  :::*                    LISTEN      937/exim4            
 +tcp6            0 :::443                  :::*                    LISTEN      21811/docker-proxy   
 +</code>
  
 ==== webdevops ==== ==== webdevops ====
Ligne 194: Ligne 319:
 By Etherpas team: By Etherpas team:
   * https://github.com/ether/etherpad-docker   * https://github.com/ether/etherpad-docker
 +
 +Une image fullstack (Etherpad-lite, Nodejs, MariaDb, Abiword & Tidy):
 +  * [[https://framagit.org/Cyrille37/docker-etherpadlite-fullstack|docker-etherpadlite-fullstack]]
 +
 +==== openssh ====
 +
 +Easily launch two hosts waiting for you on SSH port 22, with docker-compose -> https://gitlab.com/Artefacts/docker-openssh-hosts
  
 ===== Tips & tricks ===== ===== Tips & tricks =====
Ligne 201: Ligne 333:
 En cas de mise à jour de l'application, nous recréerons l'image en empaquetant la mise à jour de l'application, puis nous détruiront le conteneur pour le relancer avec l'image mis à jour. En cas de mise à jour de l'application, nous recréerons l'image en empaquetant la mise à jour de l'application, puis nous détruiront le conteneur pour le relancer avec l'image mis à jour.
 > Il est possible mais pas conseiller de faire la mise à jour d'une application dans un conteneur, on préférera mettre à jour l'image puis recréer un conteneur avec l'image mis à jour. > Il est possible mais pas conseiller de faire la mise à jour d'une application dans un conteneur, on préférera mettre à jour l'image puis recréer un conteneur avec l'image mis à jour.
 +
 +Exemple:
 +<code bash>
 +docker pull mysql
 +docker stop my-mysql-container
 +docker rm my-mysql-container
 +docker run --name=my-mysql-container --restart=always \
 +       -e MYSQL_ROOT_PASSWORD=mypwd -v /my/data/dir:/var/lib/mysql -d mysql
 +</code>
 +
 +==== Copier une image ====
 +
 +Pour utiliser une image construite sur une machine il faut l'exporter et l'importer sur l'autre machine.
 +<code>
 +# Export
 +docker save cyrille/seriously:v1 | gzip -9 > cyrille-seriously-v1.tgz
 +# Import
 +gunzip cyrille-seriously-v1.tgz | docker load
 + Loaded image: cyrille/seriously:v1
 +# Pour les images sans tag:
 +docker tag 4e1a2b349b09 some/project:v1
 +</code>
 +
 +
 +==== Faire le ménage ====
 +
 +Show docker disk usage :
 +<code bash>
 +$ docker system  df
 +TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
 +Images          42        4         3.469GB   3.038GB (87%)
 +Containers      11        0         177.4MB   177.4MB (100%)
 +Local Volumes                   688.1MB   266.4MB (38%)
 +Build Cache                     0B        0B
 +</code>
 +
 +[[https://docs.docker.com/engine/reference/commandline/system_prune/|docker system prune]]
 +
 +<code bash>
 +$ sudo docker system prune
 +WARNING! This will remove:
 +  - all stopped containers
 +  - all networks not used by at least one container
 +  - all dangling images
 +  - all dangling build cache
 +
 +Are you sure you want to continue? [y/N] y
 +...
 +</code>
 +
 +  * Remove all stopped containers : ''docker container prune'' 
 +  * Remove unused images : ''docker image prune''
 +  * Remove all unused networks : ''docker network prune''
 +
  
 ==== Container’s configuration ==== ==== Container’s configuration ====
  
   * [[http://blog.octo.com/en/docker-containers-configuration/|Docker container’s configuration]]   * [[http://blog.octo.com/en/docker-containers-configuration/|Docker container’s configuration]]
 +
 +==== Intégration système ====
 +
 +=== Démarrage du système ===
 +
 +Comment démarrer les conteneurs au démarrage du système ?
 +
 +  * [[https://docs.docker.com/engine/admin/host_integration/|Automatically start containers]]
 +    * [[https://docs.docker.com/engine/reference/run/#restart-policies-restart|Restart policies (--restart)]]
 +
 +=== Limites système ===
 +
 +  * [[https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources|Runtime constraints on resources]]
 +    * memory, swap, access, ...
 +
 +== Memory ==
 +
 +  WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.
 +
 +Il faut activer cgroup.memory
 +
 +Dans /etc/default/grub modifier:
 +  GRUB_CMDLINE_LINUX="cgroup_enable=memory"
 +Puis
 +  run update-grub2
 +  reboot
 +Et vérifier :
 +  $ cat /proc/cgroups
  
 ==== Multi Process Docker Images ==== ==== Multi Process Docker Images ====
  
   * [[http://tech.paulcz.net/2014/12/multi-process-docker-images-done-right/|Multi Process Docker Images Done Right]] by Paul Czarkowski   * [[http://tech.paulcz.net/2014/12/multi-process-docker-images-done-right/|Multi Process Docker Images Done Right]] by Paul Czarkowski
 +  * [[https://docs.docker.com/engine/admin/using_supervisord/|Using Supervisor with Docker]] on docs.docker.com
 +
 +Supervisord is a very lightweight process manager.
 +
 ==== Setting up an apt-cacher ==== ==== Setting up an apt-cacher ====
  
Ligne 247: Ligne 465:
  
 In the second instruction, replace the ''<host's-docker0-ip-here>'' command with your Docker host's IP address (at the docker0 interface) In the second instruction, replace the ''<host's-docker0-ip-here>'' command with your Docker host's IP address (at the docker0 interface)
 +
 +==== Docker Compose ====
 +
 +  * Here is a docker compose for Laravel (example) : https://github.com/edbizarro/ambientum
  
informatique/docker.1462604868.txt.gz · Dernière modification : 07/05/2016 09:07 de cyrille

Sauf mention contraire, le contenu de ce wiki est placé sous les termes de la licence suivante : CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki