issue107:c_c
                Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| issue107:c_c [2016/03/30 08:51] – créée auntiee | issue107:c_c [2016/04/18 09:06] (Version actuelle) – auntiee | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | After having set up my intel NUC (see last month’s article for more information), | + | **After having set up my intel NUC (see last month’s article for more information), | 
| - | What is Docker? | + | Après avoir installé mon NUC Intel (pour plus d' | 
| + | |||
| + | **What is Docker? | ||
| Docker is a way of creating virtualized containers for running software and services. The main difference between Docker and Vagrant is that Docker shares the base of the virtualization with all containers. So while Vagrant creates a standalone full-fledged VM, Docker instead creates a VM that uses a shared kernel between all VMs, and is based on LXC. | Docker is a way of creating virtualized containers for running software and services. The main difference between Docker and Vagrant is that Docker shares the base of the virtualization with all containers. So while Vagrant creates a standalone full-fledged VM, Docker instead creates a VM that uses a shared kernel between all VMs, and is based on LXC. | ||
| Ligne 7: | Ligne 9: | ||
| While it’s difficult to explain the difference between Vagrant and Docker in layman’s terms (as much of the differences are in the details), there are some simple things to note. For example, Docker is generally faster to start up, and less resource intensive (as it shares some of the host’s kernel). | While it’s difficult to explain the difference between Vagrant and Docker in layman’s terms (as much of the differences are in the details), there are some simple things to note. For example, Docker is generally faster to start up, and less resource intensive (as it shares some of the host’s kernel). | ||
| - | It does have to run on a Linux machine, but there are tools offered by Docker to easily set it up on Windows or Mac (using a base virtual machine to supply the linux kernel). | + | It does have to run on a Linux machine, but there are tools offered by Docker to easily set it up on Windows or Mac (using a base virtual machine to supply the linux kernel).** | 
| + | |||
| + | Qu' | ||
| + | |||
| + | Docker est une façon de créer des conteneurs virtualisés pour faire tourner des logiciels et des services. La grande différence entre Docker et Vagrant est que Docker partage la base de la virtualisation avec tous les conteneurs. Ainsi, alors que Vagrant crée une véritable VM (machine virtuelle) indépendante, | ||
| + | |||
| + | Alors qu'il est difficile d' | ||
| + | Il doit fonctionner sur une machine Linux, mais Docker fournit des outils pour s' | ||
| - | Setup | + | **Setup | 
| Docker containers can be assigned to various virtual networks, can expose ports, can run off specific images, and can share folders/ | Docker containers can be assigned to various virtual networks, can expose ports, can run off specific images, and can share folders/ | ||
| Ligne 18: | Ligne 28: | ||
| I have set up dnsmasq with a catch-all DNS entry for all subdomains of home.lan. These get forwarded to the local machine at port 80 (which is, in turn, passed to the docker HAProxy machine). HAProxy is then used to check which subdomain it is, and (if configured) points it to the correct docker container’s static IP. | I have set up dnsmasq with a catch-all DNS entry for all subdomains of home.lan. These get forwarded to the local machine at port 80 (which is, in turn, passed to the docker HAProxy machine). HAProxy is then used to check which subdomain it is, and (if configured) points it to the correct docker container’s static IP. | ||
| - | To illustrate (pelican is a static site generator): pelican.home.lan points to 192.168.1.16 (local machine) via dnsmasq. Once the request arrives, HAProxy checks the configuration file, and then passes the request through to 172.18.0.4: | + | To illustrate (pelican is a static site generator): pelican.home.lan points to 192.168.1.16 (local machine) via dnsmasq. Once the request arrives, HAProxy checks the configuration file, and then passes the request through to 172.18.0.4: | 
| - | What first? | + | Installation | 
| + | |||
| + | Docker peut être affecté à différents réseaux virtuels, « exposer » des ports, faire tourner des images spécifiques, | ||
| + | • Un réseau privé (appelé « webnet »). | ||
| + | • Un conteneur Docker utilisant HAProxy et « exposant » le port 80. Il inclut également une IP statique sur webnet. | ||
| + | • De nombreux conteneurs Docker utilisant l' | ||
| + | |||
| + | J'ai installé un dnsmasq avec une entrée DNS attrape-tout pour tous les sous-domaines de home.lan. Ils sont ensuite redirigés vers la machine locale au port 80 (qui à son tour le passe au HAProxy de la machine Docker). HAProxy vérifie alors de quel domaine il s'agit et, s'il est configuré, le renvoie vers l'IP statique du conteneur Docker correspondant. | ||
| + | |||
| + | Pour illustrer (pelican est un générateur de sites statiques) : | ||
| + | |||
| + | **What first? | ||
| First, you’ll need to create the network you want to use. | First, you’ll need to create the network you want to use. | ||
| Ligne 28: | Ligne 49: | ||
| This creates a new network called webnet, with a possible IP range of 172.18.0.0 to 172.168.255.254. I won’t go into the specifics of the format used here. If you want to use a different IP range, just adjust the 172.18 part - it’s unlikely you’ll ever need more than 65534 possible addresses for Docker containers. I chose 172.18 because the default docker IP range (which is dynamically allocated in the default network) is 172.17. That way, I should be able to always tell that the IP corresponds to docker. Do not choose the same IP range as your actual local network (typically 192.168). | This creates a new network called webnet, with a possible IP range of 172.18.0.0 to 172.168.255.254. I won’t go into the specifics of the format used here. If you want to use a different IP range, just adjust the 172.18 part - it’s unlikely you’ll ever need more than 65534 possible addresses for Docker containers. I chose 172.18 because the default docker IP range (which is dynamically allocated in the default network) is 172.17. That way, I should be able to always tell that the IP corresponds to docker. Do not choose the same IP range as your actual local network (typically 192.168). | ||
| - | The reason why we need the custom network, is simply because the default networks from docker don’t allow assigning static IPs. | + | The reason why we need the custom network, is simply because the default networks from docker don’t allow assigning static IPs.** | 
| - | How do I go about creating my machines? | + | Par où commencer ? | 
| + | |||
| + | Il faut d' | ||
| + | |||
| + | docker network create --subnet=172.18.0.0/ | ||
| + | |||
| + | Cela crée un nouveau réseau appelé webnet avec des adresses IP allant de 172.18.0.0 jusqu' | ||
| + | |||
| + | La raison pour laquelle nous avons besoin d'un réseau particulier vient simplement du fait que le réseau par défaut de Docker ne permet pas  d' | ||
| + | |||
| + | **How do I go about creating my machines? | ||
| The standard docker command will pretty much always be the same. | The standard docker command will pretty much always be the same. | ||
| Ligne 43: | Ligne 74: | ||
| • --ip 172.18.0.X - this is the static IP I’m assigning. I like to keep them in a basic order, in order to make adding HAProxy entries easier. If you chose a different IP range in the step above, adjust accordingly. | • --ip 172.18.0.X - this is the static IP I’m assigning. I like to keep them in a basic order, in order to make adding HAProxy entries easier. If you chose a different IP range in the step above, adjust accordingly. | ||
| • --name {name} - this is the name the docker instance will be known as. For example --name pelican. This can be used in the docker start/ | • --name {name} - this is the name the docker instance will be known as. For example --name pelican. This can be used in the docker start/ | ||
| - | • {IMAGE} - this is the image to use for the base of the container. I like the nickistre/ | + | • {IMAGE} - this is the image to use for the base of the container. I like the nickistre/ | 
| - | In the case of the HAProxy image (which should be created first), the command will look like this: | + | Comment s'y prendre pour créer mes machines ? | 
| + | |||
| + | La commande standard de Docker sera toujours à peu près la même. | ||
| + | |||
| + | docker run -d -v {SHARE} --net webnet --ip 172.18.0.X --name {NAME} {IMAGE} | ||
| + | |||
| + | Ce qu' | ||
| + | • « docker run » crée un conteneur. | ||
| + | • -d détache le conteneur créé (sinon toutes les sorties du conteneur seront automatiquement envoyées vers le terminal et la fermeture du terminal fermera l' | ||
| + | • -v{SHARE} donne l' | ||
| + | • --net webnet configure le réseau que doit utiliser le conteneur. | ||
| + | • --ip 172.18.0.X il s'agit de l'IP statique que je donne. J'aime les avoir bien organisés de façon à rendre plus facile l' | ||
| + | • --name{name} c'est le nom sous lequel l' | ||
| + | • {IMAGE} il s'agit de l' | ||
| + | |||
| + | **In the case of the HAProxy image (which should be created first), the command will look like this: | ||
| docker run -d -v ~/ | docker run -d -v ~/ | ||
| Ligne 51: | Ligne 97: | ||
| Main differences: | Main differences: | ||
| • -p 80:80 - exposes the guest port 80 to the host port 80 (so visiting 172.18.0.2 in a web browser should spit out the typical 503 error from HAProxy). | • -p 80:80 - exposes the guest port 80 to the host port 80 (so visiting 172.18.0.2 in a web browser should spit out the typical 503 error from HAProxy). | ||
| - | • -v - in the command above, I just like the actual HAProxy.cfg file into the location for the config for HAProxy. NOTE: editing this file with some text editors (such as vim) will result in HAProxy not accepting the changes. This is due to the inode changing. To fix, just restart the machine with ‘docker restart proxy’. Nano appears to avoid this problem. | + | • -v - in the command above, I just like the actual HAProxy.cfg file into the location for the config for HAProxy. NOTE: editing this file with some text editors (such as vim) will result in HAProxy not accepting the changes. This is due to the inode changing. To fix, just restart the machine with ‘docker restart proxy’. Nano appears to avoid this problem.** | 
| - | Autostarting | + | Dans le cas de l' | 
| + | |||
| + | config/ | ||
| + | |||
| + | Différences principales : | ||
| + | • -p 80:80 expose le port invité 80 au port hôte 80 (donc en allant à l' | ||
| + | • -v dans la commande ci-dessus, j'aime bien avoir le fichier de configuration HAProxy original à l' | ||
| + | |||
| + | **Autostarting | ||
| If you want the docker containers to always run (after crashing, reboots, or restarts), you can add --restart=always to the run command. This must be done when creating the container - so if you’ve already created one, you’ll need to stop it, remove it (rm), and then recreate it. | If you want the docker containers to always run (after crashing, reboots, or restarts), you can add --restart=always to the run command. This must be done when creating the container - so if you’ve already created one, you’ll need to stop it, remove it (rm), and then recreate it. | ||
| Ligne 59: | Ligne 113: | ||
| Does this work for only port 80? | Does this work for only port 80? | ||
| - | The settings for the HAProxy container should never need to change (during docker run). However, if you want to point a domain to, for example, a NodeJS application running on 8000, just adjust the IP in the HAProxy configuration (see below). For example, 172.18.0.6: | + | The settings for the HAProxy container should never need to change (during docker run). However, if you want to point a domain to, for example, a NodeJS application running on 8000, just adjust the IP in the HAProxy configuration (see below). For example, 172.18.0.6: | 
| - | HAProxy Config | + | Démarrage automatique | 
| - | I’ve saved an example of my configuration here: http:// | + | Si vous voulez que les conteneurs Docker soient toujours en fonction (après un crash, un redémarrage du système ou de session), vous pouvez ajouter –restart=always à la commande run. Ceci doit être fait à la création du conteneur. Donc, si vous en avez déjà créé un, vous devez l' | 
| - | Basically, adding new containers is as simple as copying the acl line (#33), the use_backend line (#36), and the backend block (#39-43). Be sure to keep increasing the index numbers (host_test1 would become host_test2, etc.). And give each backend a unique name (and adjust the IP!). | + | Cela ne fonctionne-t-il que pour le port 80 ? | 
| - | How do I make a wildcard dnsmasq entry? | + | Les réglages du HAProxy ne devraient jamais changer (pendant le fonctionnement de Docker). Toutefois, si vous voulez pointer un domaine particulier, | 
| - | You can add a single line to your dnsmasq.conf file (typically found at / | + | **HAProxy Config | 
| - | address=/home.lan/192.168.1.16 | + | I’ve saved an example of my configuration here: http://pastebin.com/1M5DMkF3 | 
| - | Replace | + | Basically, adding new containers is as simple as copying | 
| - | I hope this article was helpful to anyone wondering about Docker, who has been looking for a better way to host local projects while in development. If you have any questions, or want to share a docker trick of your own, feel free to email me at lswest34+fcm@gmail.com. | + | Configuration du HAProxy | 
| + | J'ai sauvegardé un exemple de ma configuration ici : http:// | ||
| + | Pratiquement, | ||
| + | **How do I make a wildcard dnsmasq entry? | ||
| + | You can add a single line to your dnsmasq.conf file (typically found at / | ||
| + | address=/ | ||
| + | Replace the IP with your own, and the home.lan portion with the domain you’d like (minus any subdomains - so instead of www.google.com, | ||
| + | Comment faire une entrée générique pour DNSMASQ ? | ||
| + | Vous pouvez ajouter une simple ligne à votre fichier dnsmasq.conf (que vous trouverez normalement à / | ||
| + | address=/ | ||
| + | Remplacez l'IP par la vôtre et la partie home.lan avec le domaine de votre choix (sans les sous-domaines, | ||
| + | **I hope this article was helpful to anyone wondering about Docker, who has been looking for a better way to host local projects while in development. If you have any questions, or want to share a docker trick of your own, feel free to email me at lswest34+fcm@gmail.com.** | ||
| + | J' | ||
| - | Further Reading | + | |
| + | **Further Reading | ||
| https:// | https:// | ||
| Ligne 96: | Ligne 163: | ||
| https:// | https:// | ||
| Docker VS Vagrant | Docker VS Vagrant | ||
| + | |||
| + | https:// | ||
| + | Docker** | ||
| + | |||
| + | Pour aller plus loin | ||
| + | |||
| + | https:// | ||
| + | LXC | ||
| + | |||
| + | https:// | ||
| + | Comparaison entre Docker et Vagrant | ||
| https:// | https:// | ||
| Docker | Docker | ||
issue107/c_c.1459320667.txt.gz · Dernière modification : 2016/03/30 08:51 de auntiee
                
                