Depuis plusieurs mois, j'utilise Docker pour mes environnements de développement sur les nouveaux projets.

Voyons comment mettre en place un environnement simple.

Docker

Docker a fait une entrée remarquée dans le paysage des outils DevOps. Là où Vagrant permettait de créer un environnement de développement quasi identique à celui de production, mais avec des temps de création de VM longs et des images qui prennent beaucoup de place (centaines de Mo), Docker a bousculé les pratiques pour un résultat identique, mais avec une réactivité impressionnante et une utilisation limitée de l'espace disque.

Premiers pas

Je ne détaillerai pas l'installation de Docker ou de Docker Compose. Je vous laisse consulter la documentation en fonction de votre système.

Voici un bon tuto pour se familiariser avec Docker.

Les exemples présentés ici ont été testés sous Linux (Fedora) avec les versions suivantes :

$ docker -v
Docker version 1.12.1, build 23cf638
$ docker-compose -v
docker-compose version 1.7.1, build 6c29830

Pour organiser notre projet, nous allons créer l'arborescence suivante :

.
├── docker
└── magento

Dans le répertoire Docker, nous mettrons la configuration des containers Docker.

Dans magento, nous retrouverons nos sources Magento.

Nous allons faire simple, et pour cela, nous ne créerons pas tout de suite notre propre container mais nous utiliserons des containers existants.

Et nous allons commencer avec :

  • Nginx (dernière version)

Créons un premier fichier docker/docker-compose.yml :

version: '2'
services:
  nginx:
    image: nginx:alpine
    ports:
      - "81:80"

Le conteneur Nginx écoutera sur le port 81 de l'hôte et le dossier racine des ressources à servir sera monté en volume avec notre dossier magento créé précédemment.

Dans le répertoire approprié, lançons docker-compose en mode détaché (-d) :

$ cd docker
$ docker-compose up -d
Pulling nginx (nginx:alpine)...
alpine: Pulling from library/nginx
c0cb142e4345: Already exists
550be1410575: Pull complete
f89cfc3ca4f4: Pull complete
269d010cc2b4: Pull complete
Digest: sha256:36b95728c0d9b6668bb8e4aa31476de27aeedbeba07dcddb6821b76fb72830b2
Status: Downloaded newer image for nginx:alpine
Creating docker_nginx_1

On peut lister les containers lancés :

$ docker-compose ps
   Name              Command          State              Ports            
---------------------------------------------------------------------------
docker_nginx_1   nginx -g daemon off;   Up      443/tcp, 0.0.0.0:81->80/tcp 

Bon, ça tourne, mais comment voir le résultat ? En allant dans un navigateur, pardi !

Screenshot Nginx

Et on peut consulter les logs du container :

$ docker-compose logs
Attaching to docker_nginx_1
nginx_1  | 172.23.0.1 - - [14/Oct/2016:13:44:36 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0" "-"

Bon, on a Nginx prêt à servir du contenu.

Modifions la configuration Docker Composer en ajoutant ceci à la fin de notre fichier docker-compose.yml :

    volumes:
      - ../magento:/usr/share/nginx/html

Cette configuration permet de mapper le dossier ../magento de notre machine hôte avec le path /usr/share/nginx/html du conteneur Nginx (chemin par défaut). Tout fichier dans ce dossier sera servi par notre serveur.

Créons donc un fichier bidon dans le dossier magento :

$ echo "<h1>Hello</h1>" > ../magento/index.html

Arrêtons, détruisons notre conteneur, puis relançons-le :

$ docker-compose down
Stopping docker_nginx_1 ... done
Removing docker_nginx_1 ... done
Removing network docker_default
$ docker-compose up -d        
Creating network "docker_default" with the default driver
Creating docker_nginx_1

Dans le navigateur, on voit bien notre titre :

Screenshot Nginx

Conteneur PHP

Très bien, mais il va falloir maintenant interpréter du PHP...

Ajoutons un peu de configuration à notre fichier docker-compose.yml pour avoir un conteneur basé sur l'image appropriée :

[...]
  php:
    image: php:5.6-fpm-alpine
    volumes:
      - ../magento:/var/www/html

Ce qui va nous créer un nouveau conteneur pour le service PHP.

Il faut que Nginx soit lié à notre conteneur PHP et qu'il appelle PHP-FPM pour interpréter les fichiers PHP. Pour cela, nous allons réécrire le fichier de configuration (en tant que volume) qui sera pris en compte par Nginx.

On modifie notre fichier docker-compose.yml comme suit ;

[...]
  nginx:
[...]
    links:
      - "php"
    volumes:
      - ../magento:/var/www/html
      - ./mysite.conf:/etc/nginx/conf.d/default.conf
[...]

Il faut aussi créer le fichier mysite.conf avec le contenu suivant :

server {
    listen       80;
    server_name  localhost;

    root   /var/www/html;
    index  index.php index.html index.htm;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

Et si on ajoute un fichier index.php avec une bête commande PHP :

$ echo "<h1><?php date_default_timezone_set('UTC'); echo date('d/m/Y H:i:s'); ?></h1>" > ../magento/index.php

On peut voir le résultat dans le navigateur :

Screenshot Nginx

Voici le fichier docker-compose.yml final :

version: '2'
services:
  nginx:
    image: nginx:alpine
    ports:
      - "81:80"
    links:
      - "php"
    volumes:
      - ../magento:/var/www/html
      - ./mysite.conf:/etc/nginx/conf.d/default.conf
  php:
    image: php:5.6-fpm-alpine
    volumes:
      - ../magento:/var/www/html

Conclusion

On a terminé la première partie de ce tutoriel.

Le gros intérêt, c'est qu'en versionnant les fichiers Docker, on partage avec son équipe la même configuration d'environnement de développement.

Ajouter un commentaire

Commentaires

http://mewkid.net/buy-amoxicillin/ - Amoxicillin 500mg Amoxicillin 500 Mg ehz.edow.meliweb.fr.imu.qo http://mewkid.net/buy-amoxicillin/
Écrit le Fri, 31 May 2019 15:44:46 par oxivequqebal
http://mewkid.net/buy-amoxicillin/ - Amoxicillin 500 Amoxicillin No Prescription kbm.gzia.meliweb.fr.dgo.bp http://mewkid.net/buy-amoxicillin/
Écrit le Fri, 31 May 2019 15:16:12 par eojosefiris
http://mewkid.net/buy-amoxicillin/ - Amoxicillin Without Prescription Amoxicillin No Prescription vak.rjsf.meliweb.fr.ggq.yr http://mewkid.net/buy-amoxicillin/
Écrit le Wed, 29 May 2019 09:39:42 par eqiuoveg
http://mewkid.net/buy-amoxicillin/ - Amoxicillin Amoxicillin Online jls.cuol.meliweb.fr.ncu.js http://mewkid.net/buy-amoxicillin/
Écrit le Wed, 29 May 2019 09:13:36 par izbomqikaxiwe
Hey. Soon your hosting account and your domain meliweb.fr will be blocked forever, and you will receive tens of thousands of negative feedback from angry people. Pay me 0.5 BTC until June 1, 2019. Otherwise, you will get the reputation of a malicious spammer, your site meliweb.fr will be blocked for life and you will be sued for insulting believers. I guarantee this to you. My bitcoin wallet:19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL Here is a list of what you get if you don’t follow my requirements: abuse spamhouse for aggressive web spam tens of thousands of negative reviews about you and your website from angry people for aggressive web and email spam lifetime blocking of your hosting account for aggressive web and email spam lifetime blocking of your domain for aggressive web and email spam Thousands of angry complaints from angry people will come to your mail and messengers for sending you a lot of spam complete destruction of your reputation and loss of clients forever for a full recovery from the damage you need tens of thousands of dollars All of the above will result in blocking your domain and hosting account for life. The price of your peace of mind is 0.5 BTC. Do you want this? If you do not want the above problems, then before June 1, 2019, you need to send me 0.5 BTC to my Bitcoin wallet: 19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL How do I do all this to get this result: 1. I will send messages to 33 000 000 sites with contact forms with offensive messages with the address of your site, that is, in this situation, you and the spammer and insult people. And everyone will not care that it is not you. 2. I’ll send messages to 19,000,000 email addresses and very intrusive advertisements for making money and offer a free iPhone with your website address meliweb.fr and your contact details. And then send out abusive messages with the address of your site. 3. I will do aggressive spam on blogs, forums and other sites (in my database there are 35 978 370 sites and 315 900 sites from which you will definitely get a huge amount of abuse) of your site meliweb.fr. After such spam, the spamhouse will turn its attention on you and after several abuses your host will be forced to block your account for life. Your domain registrar will also block your domain permanently. All of the above will result in blocking your domain and hosting account for life. If you do not want to receive thousands of complaints from users and your hosting provider, then pay before June 1, 2019. The price of your peace of mind is 0.5 BTC. Otherwise, I will send your site through tens of millions of sites that will lead to the blocking of your site for life and you will lose everything and your reputation as well. But get a reputation as a malicious spammer. My bitcoin wallet:19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL
Écrit le Sun, 26 May 2019 19:33:58 par Patricksob
Hey. Soon your hosting account and your domain meliweb.fr will be blocked forever, and you will receive tens of thousands of negative feedback from angry people. Pay me 0.5 BTC until June 1, 2019. Otherwise, you will get the reputation of a malicious spammer, your site meliweb.fr will be blocked for life and you will be sued for insulting believers. I guarantee this to you. My bitcoin wallet:19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL Here is a list of what you get if you don’t follow my requirements: abuse spamhouse for aggressive web spam tens of thousands of negative reviews about you and your website from angry people for aggressive web and email spam lifetime blocking of your hosting account for aggressive web and email spam lifetime blocking of your domain for aggressive web and email spam Thousands of angry complaints from angry people will come to your mail and messengers for sending you a lot of spam complete destruction of your reputation and loss of clients forever for a full recovery from the damage you need tens of thousands of dollars All of the above will result in blocking your domain and hosting account for life. The price of your peace of mind is 0.5 BTC. Do you want this? If you do not want the above problems, then before June 1, 2019, you need to send me 0.5 BTC to my Bitcoin wallet: 19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL How do I do all this to get this result: 1. I will send messages to 33 000 000 sites with contact forms with offensive messages with the address of your site, that is, in this situation, you and the spammer and insult people. And everyone will not care that it is not you. 2. I’ll send messages to 19,000,000 email addresses and very intrusive advertisements for making money and offer a free iPhone with your website address meliweb.fr and your contact details. And then send out abusive messages with the address of your site. 3. I will do aggressive spam on blogs, forums and other sites (in my database there are 35 978 370 sites and 315 900 sites from which you will definitely get a huge amount of abuse) of your site meliweb.fr. After such spam, the spamhouse will turn its attention on you and after several abuses your host will be forced to block your account for life. Your domain registrar will also block your domain permanently. All of the above will result in blocking your domain and hosting account for life. If you do not want to receive thousands of complaints from users and your hosting provider, then pay before June 1, 2019. The price of your peace of mind is 0.5 BTC. Otherwise, I will send your site through tens of millions of sites that will lead to the blocking of your site for life and you will lose everything and your reputation as well. But get a reputation as a malicious spammer. My bitcoin wallet:19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL
Écrit le Sun, 26 May 2019 19:33:53 par BrandonSig
Hey. Soon your hosting account and your domain meliweb.fr will be blocked forever, and you will receive tens of thousands of negative feedback from angry people. Pay me 0.5 BTC until June 1, 2019. Otherwise, you will get the reputation of a malicious spammer, your site meliweb.fr will be blocked for life and you will be sued for insulting believers. I guarantee this to you. My bitcoin wallet:19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL Here is a list of what you get if you don’t follow my requirements: abuse spamhouse for aggressive web spam tens of thousands of negative reviews about you and your website from angry people for aggressive web and email spam lifetime blocking of your hosting account for aggressive web and email spam lifetime blocking of your domain for aggressive web and email spam Thousands of angry complaints from angry people will come to your mail and messengers for sending you a lot of spam complete destruction of your reputation and loss of clients forever for a full recovery from the damage you need tens of thousands of dollars All of the above will result in blocking your domain and hosting account for life. The price of your peace of mind is 0.5 BTC. Do you want this? If you do not want the above problems, then before June 1, 2019, you need to send me 0.5 BTC to my Bitcoin wallet: 19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL How do I do all this to get this result: 1. I will send messages to 33 000 000 sites with contact forms with offensive messages with the address of your site, that is, in this situation, you and the spammer and insult people. And everyone will not care that it is not you. 2. I’ll send messages to 19,000,000 email addresses and very intrusive advertisements for making money and offer a free iPhone with your website address meliweb.fr and your contact details. And then send out abusive messages with the address of your site. 3. I will do aggressive spam on blogs, forums and other sites (in my database there are 35 978 370 sites and 315 900 sites from which you will definitely get a huge amount of abuse) of your site meliweb.fr. After such spam, the spamhouse will turn its attention on you and after several abuses your host will be forced to block your account for life. Your domain registrar will also block your domain permanently. All of the above will result in blocking your domain and hosting account for life. If you do not want to receive thousands of complaints from users and your hosting provider, then pay before June 1, 2019. The price of your peace of mind is 0.5 BTC. Otherwise, I will send your site through tens of millions of sites that will lead to the blocking of your site for life and you will lose everything and your reputation as well. But get a reputation as a malicious spammer. My bitcoin wallet:19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL
Écrit le Sun, 26 May 2019 19:33:52 par RichieDen
Hey. Soon your hosting account and your domain meliweb.fr will be blocked forever, and you will receive tens of thousands of negative feedback from angry people. Pay me 0.5 BTC until June 1, 2019. Otherwise, you will get the reputation of a malicious spammer, your site meliweb.fr will be blocked for life and you will be sued for insulting believers. I guarantee this to you. My bitcoin wallet:19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL Here is a list of what you get if you don’t follow my requirements: abuse spamhouse for aggressive web spam tens of thousands of negative reviews about you and your website from angry people for aggressive web and email spam lifetime blocking of your hosting account for aggressive web and email spam lifetime blocking of your domain for aggressive web and email spam Thousands of angry complaints from angry people will come to your mail and messengers for sending you a lot of spam complete destruction of your reputation and loss of clients forever for a full recovery from the damage you need tens of thousands of dollars All of the above will result in blocking your domain and hosting account for life. The price of your peace of mind is 0.5 BTC. Do you want this? If you do not want the above problems, then before June 1, 2019, you need to send me 0.5 BTC to my Bitcoin wallet: 19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL How do I do all this to get this result: 1. I will send messages to 33 000 000 sites with contact forms with offensive messages with the address of your site, that is, in this situation, you and the spammer and insult people. And everyone will not care that it is not you. 2. I’ll send messages to 19,000,000 email addresses and very intrusive advertisements for making money and offer a free iPhone with your website address meliweb.fr and your contact details. And then send out abusive messages with the address of your site. 3. I will do aggressive spam on blogs, forums and other sites (in my database there are 35 978 370 sites and 315 900 sites from which you will definitely get a huge amount of abuse) of your site meliweb.fr. After such spam, the spamhouse will turn its attention on you and after several abuses your host will be forced to block your account for life. Your domain registrar will also block your domain permanently. All of the above will result in blocking your domain and hosting account for life. If you do not want to receive thousands of complaints from users and your hosting provider, then pay before June 1, 2019. The price of your peace of mind is 0.5 BTC. Otherwise, I will send your site through tens of millions of sites that will lead to the blocking of your site for life and you will lose everything and your reputation as well. But get a reputation as a malicious spammer. My bitcoin wallet:19ckouUP2E22aJR5BPFdf7jP2oNXR3bezL
Écrit le Sun, 26 May 2019 18:33:37 par Joshuascorp
Effexor Xr Online Canada Viagra Wikipedia Tretinoin cheapest cialis 20mg isotretinoin free shipping Buy Generic Viagra
Écrit le Sun, 12 May 2019 09:00:38 par Ellalkapy
Viagra Testen Kostenlos Free Viagra Sample Before Buying buy generic cialis online Lasix Online No Prescription best buy isotretinoin Cheapest Us Pharmacy For Viagra
Écrit le Fri, 10 May 2019 06:46:27 par LesAcidly
Viagra Ibiza Cialis Original Generique buy generic cialis Foros Donde Comprar Viagra Dutasteride Bph Online Pharmacy Propecia Renova
Écrit le Sat, 04 May 2019 19:38:42 par Ellalkapy
Prix Viagra Pharmacie Suisse cheapest cialis 20mg Que Es Cialis Y Como Se Toma Strep Throat Amoxicillin Walmart Prescription Prices
Écrit le Fri, 12 Apr 2019 19:55:05 par MatCeal
http://theprettyguineapig.com/amoxicillin/ - 18 Amoxicillin Without Prescription http://theprettyguineapig.com/amoxicillin/
Écrit le Tue, 26 Mar 2019 13:26:56 par uwoseqikalu
bWVsaXdlYi5mcg## isazemaja-a.anchor.com [URL=http://theprettyguineapig.com/generic-cialis/#isazemaja-u]isazemaja-u.anchor.com[/URL] http://theprettyguineapig.com/generic-cialis/#isazemaja-t http://theprettyguineapig.com/generic-cialis/#isazemaja-t http://theprettyguineapig.com/generic-cialis/#isazemaja-t http://theprettyguineapig.com/generic-cialis/#isazemaja-t http://theprettyguineapig.com/generic-cialis/#isazemaja-t http://theprettyguineapig.com/generic-cialis/#isazemaja-t http://theprettyguineapig.com/generic-cialis/#isazemaja-t http://theprettyguineapig.com/generic-cialis/#isazemaja-t ugiteak
Écrit le Tue, 26 Mar 2019 12:57:35 par ogosuy
bWVsaXdlYi5mcg## iokelijip-a.anchor.com [URL=http://theprettyguineapig.com/generic-cialis/#iokelijip-u]iokelijip-u.anchor.com[/URL] http://theprettyguineapig.com/generic-cialis/#iokelijip-t http://theprettyguineapig.com/generic-cialis/#iokelijip-t http://theprettyguineapig.com/generic-cialis/#iokelijip-t http://theprettyguineapig.com/generic-cialis/#iokelijip-t http://theprettyguineapig.com/generic-cialis/#iokelijip-t http://theprettyguineapig.com/generic-cialis/#iokelijip-t http://theprettyguineapig.com/generic-cialis/#iokelijip-t http://theprettyguineapig.com/generic-cialis/#iokelijip-t egqiyi
Écrit le Tue, 26 Mar 2019 12:57:34 par itokozub
bWVsaXdlYi5mcg## usacaiz-a.anchor.com [URL=http://theprettyguineapig.com/generic-cialis/#usacaiz-u]usacaiz-u.anchor.com[/URL] http://theprettyguineapig.com/generic-cialis/#usacaiz-t http://theprettyguineapig.com/generic-cialis/#usacaiz-t http://theprettyguineapig.com/generic-cialis/#usacaiz-t http://theprettyguineapig.com/generic-cialis/#usacaiz-t http://theprettyguineapig.com/generic-cialis/#usacaiz-t http://theprettyguineapig.com/generic-cialis/#usacaiz-t http://theprettyguineapig.com/generic-cialis/#usacaiz-t http://theprettyguineapig.com/generic-cialis/#usacaiz-t wegzijs
Écrit le Tue, 26 Mar 2019 12:57:32 par eqicut
http://theprettyguineapig.com/amoxicillin/ - Amoxicillin 500mg Capsules Generic Amoxicillin 500 Mg http://theprettyguineapig.com/amoxicillin/
Écrit le Tue, 26 Mar 2019 12:45:39 par katarefurfu
http://theprettyguineapig.com/amoxicillin/ - Amoxicillin Amoxicillin Without Prescription http://theprettyguineapig.com/amoxicillin/
Écrit le Tue, 26 Mar 2019 09:54:35 par aveyasofobe
http://theprettyguineapig.com/amoxicillin/ - 18 Buy Amoxicillin Online http://theprettyguineapig.com/amoxicillin/
Écrit le Tue, 26 Mar 2019 09:28:39 par udoodetez
how to make money online with your own website: how 2 earn money online earn money online 2018 philippines how 2 earn money online india 5 ways earn money online earn money online youtube hindi Popular Tags: earn money online iphonehow to make money with android developmentearn money online through amazonhow to make cash online from homehow can i make money with online surveysmake money online using instagramhow to create a mobile app and make moneymake money online referral codemake money online in japanhow to make real money eve onlineearn money fast online australiahow to earn money online uk 2018get money online surveyhow to make money online in canada legallyhow do you make money writing onlinemaking money online side businessmake money online legit websitesmake easy money online paypalearn money online paypal surveyshow to make money from betting on footballearn money by surveys onlineeve online how do corporations make moneyhow to earn money online in bangladeshtop 10 money earn appsonline quiz win money
Écrit le Fri, 23 Nov 2018 18:09:19 par Anthonyblafe

Article précédent