---
title: "Docker : Deuxième pas ou après « Hello world »."
url: https://www.cyber-neurones.org/2016/04/docker-deuxieme-pas-ou-apres-hello-world/
date: 2016-04-14
modified: 2017-09-06
author: "Frederic"
description: "Attention ceci est mon brouillon avant de faire une belle documentation sur Docker (il y a à boire et à manger).  Fort de mon expérience du premier POST ( https://www.cyber-neurones.org/2016/04/docker-les-premiers-pas/ ),..."
categories:
  - "Docker"
tags:
  - "Docker"
  - "Oracle Linux"
  - "Virtual Box"
image: https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-14.51.24.png
word_count: 1492
---

# Docker : Deuxième pas ou après « Hello world ».

**Attention ceci est mon brouillon avant de faire une belle documentation sur Docker (il y a à boire et à manger). **

Fort de mon expérience du premier POST ( [https://www.cyber-neurones.org/2016/04/docker-les-premiers-pas/](https://www.cyber-neurones.org/2016/04/docker-les-premiers-pas/) ), je vais refaire une installation. J'ai pu voir qu'il me fallait **16 Go** pour le "mkfs.btrfs" et j'ai vu que l'installation faisait **2 Go**. Je vais donc garder 2 Go de plus, ce qui fait que je vais donc faire une installation à **20 Go**.

[![Capture d’écran 2016-04-14 à 14.51.24](https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-14.51.24.png)](https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-14.51.24.png)

Et voici la nouvelle création sur Virtual Box :

[![Capture d’écran 2016-04-14 à 10.49.32](https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-10.49.32.png)](https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-10.49.32.png) [![Capture d’écran 2016-04-14 à 10.49.57](https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-10.49.57.png)](https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-10.49.57.png)

En bref, on fait l'installation, on fait le pont d'accès, on supprime selinux, on fait l'update du kernel, et pour finir on fait l'installation de docker-engine, et un petit reboot.

Attention pendant l'installation d'Oracle Linux, il faut faire ceci :

[![Capture d’écran 2016-04-14 à 11.43.43](https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-11.43.43.png)](https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-11.43.43.png) [![Capture d’écran 2016-04-14 à 11.51.33](https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-11.51.33.png)](https://www.cyber-neurones.org/wp-content/uploads/2016/04/cyber-neurones_capture-d’ecran-2016-04-14-a-11.51.33.png)

On croise les doigts pour que la création puisse se faire vu que l'on a suffisamment d'espace disque.
[root@localhost ~]# ln -s /docker/ /var/lib/docker
[root@localhost ~]# df
Sys. de fichiers blocs de 1K Utilisé Disponible Uti% Monté sur
/dev/sda2 4278272 2042148 2236124 48% /
devtmpfs 370420 0 370420 0% /dev
tmpfs 380116 0 380116 0% /dev/shm
tmpfs 380116 5164 374952 2% /run
tmpfs 380116 0 380116 0% /sys/fs/cgroup
/dev/sda1 17825792 544 15699712 1% /docker
tmpfs 76024 0 76024 0% /run/user/0
[root@localhost ~]# df -h
Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur
/dev/sda2 4,1G 2,0G 2,2G 48% /
devtmpfs 362M 0 362M 0% /dev
tmpfs 372M 0 372M 0% /dev/shm
tmpfs 372M 5,1M 367M 2% /run
tmpfs 372M 0 372M 0% /sys/fs/cgroup
**/dev/sda1 17G 544K 15G 1% /docker**
tmpfs 75M 0 75M 0% /run/user/0
[root@localhost ~]# **yum install docker-engine**
Modules complémentaires chargés : ulninfo
Résolution des dépendances
...
[root@localhost ~]# **service docker start**
Redirecting to /bin/systemctl start docker.service
[root@localhost ~]# **chkconfig docker on**
Note : transfert de la requête par « systemctl enable docker.service ».
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

Modification de **updated.conf** pour ne pas faire de recherche dans Docker .
[root@localhost ~]# cat /etc/updatedb.conf
PRUNE_BIND_MOUNTS = "yes"
PRUNEFS = "9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset debugfs devpts ecryptfs exofs fuse fuse.sshfs fusectl gfs gfs2 hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs"
PRUNENAMES = ".git .hg .svn"
PRUNEPATHS = "/afs /media /mnt **/var/lib/docker** /net /sfs /tmp /udev /var/cache/ccache /var/lib/yum/yumdb /var/spool/cups /var/spool/squid /var/tmp"

Roulement de tambour, est-ce que cela a fonctionné ? Ou alors ce n'est toujours pas bon ...
[root@localhost ~]# docker run -it --rm --name haproxy-syntax-check haproxy:1.5 haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg
Unable to find image 'haproxy:1.5' locally
1.5: Pulling from library/haproxy
efd26ecc9548: Pull complete
a3ed95caeb02: Pull complete
545a1e51c226: Pull complete
4f8fd706ca7d: Pull complete
c7652a33f7e1: Pull complete
Digest: sha256:8970d415c69e563a2729b2d1d123f743daef86757b965686f12b1f840cab13da
Status: Downloaded newer image for haproxy:1.5
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -c -f /usr/local/etc/haproxy/haproxy.cfg -Ds
[ALERT] 104/130317 (6) : Could not open configuration file /usr/local/etc/haproxy/haproxy.cfg : No such file or directory
haproxy-systemd-wrapper: exit, haproxy RC=256

La première erreur vient du fait que le fichier /usr/local/etc/haproxy/haproxy.cfg n'est pas présent. Je vais donc prendre un fichier basique sur le net.
[root@localhost ~]# mkdir /usr/local/etc/haproxy

[root@localhost ~]# vi /usr/local/etc/haxproxy/haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
user haproxy
group haproxy
maxconn 1024
daemon

defaults
log global
mode http
option httplog
option dontlognull

#
# Listen on *:80 - Send traffic to the backend named "apache"
#
frontend www-http
bind *:80
default_backend apache

#
# Back-end definition.
#
backend apache
mode http
balance roundrobin
server web1 10.0.0.10:8080
server web2 10.0.0.20:8080
server web3 10.0.0.30:8080
server web4 10.0.0.40:8080

[root@localhost ~]# adduser haproxy

On refait le test mais on a toujours la même erreur, car on ne résonne pas en conteneur.
[root@localhost ~]# docker run -it --rm --name haproxy-syntax-check haproxy:1.5 haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -c -f /usr/local/etc/haproxy/haproxy.cfg -Ds
[ALERT] 104/131841 (6) : Could not open configuration file **/usr/local/etc/haproxy/haproxy.cfg** : No such file or directory
haproxy-systemd-wrapper: exit, haproxy RC=256
[root@localhost ~]# cat **/usr/local/etc/haproxy/haproxy.cfg**
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
user haproxy
group haproxy
maxconn 1024
daemon

defaults
log global
mode http
option httplog
option dontlognull

#
# Listen on *:80 - Send traffic to the backend named "apache"
#
frontend www-http
bind *:80
default_backend apache

#
# Back-end definition.
#
backend apache
mode http
balance roundrobin
server web1 10.0.0.10:8080
server web2 10.0.0.20:8080
server web3 10.0.0.30:8080
server web4 10.0.0.40:8080

[root@localhost ~]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
haproxy 1.5 011e001101c0 19 hours ago 138.2 MB

Si on fait cela de façon sale, on arrive à un début de solution (à noter que le locate fonctionne car je n'ai pas fait de reboot, sinon j'ai interdit le passage dans /docker/ à mlocate):
[root@localhost ~]# locate "/usr/local/sbin/haproxy"
/docker/btrfs/subvolumes/2fe19a89b016b3521418f06de0bec2b54df0933294873630333d88da924a95d4/usr/local/sbin/haproxy
/docker/btrfs/subvolumes/2fe19a89b016b3521418f06de0bec2b54df0933294873630333d88da924a95d4/usr/local/sbin/haproxy-systemd-wrapper
/docker/btrfs/subvolumes/3922cbb258a566dfc4b4c9c0cb183a83b93353e6a66aadfdac080d741d2b59ea/usr/local/sbin/haproxy
/docker/btrfs/subvolumes/3922cbb258a566dfc4b4c9c0cb183a83b93353e6a66aadfdac080d741d2b59ea/usr/local/sbin/haproxy-systemd-wrapper
/docker/btrfs/subvolumes/a57fb85ecf435baab5bc2ceafc70ee00527f6b379dc0c9366c748f1563332376/usr/local/sbin/haproxy
/docker/btrfs/subvolumes/a57fb85ecf435baab5bc2ceafc70ee00527f6b379dc0c9366c748f1563332376/usr/local/sbin/haproxy-systemd-wrapper
/docker/btrfs/subvolumes/f0e08f7411c330363784c15ae4633fe7f14ed6fabf2dc5ffcd3fac1559cb2861/usr/local/sbin/haproxy
/docker/btrfs/subvolumes/f0e08f7411c330363784c15ae4633fe7f14ed6fabf2dc5ffcd3fac1559cb2861/usr/local/sbin/haproxy-systemd-wrapper
[root@localhost ~]# cp /usr/local/etc/haproxy/haproxy.cfg /docker/btrfs/subvolumes/2fe19a89b016b3521418f06de0bec2b54df0933294873630333d88da924a95d4/usr/local/etc/haproxy/.
[root@localhost ~]# cp /usr/local/etc/haproxy/haproxy.cfg /docker/btrfs/subvolumes/3922cbb258a566dfc4b4c9c0cb183a83b93353e6a66aadfdac080d741d2b59ea/usr/local/etc/haproxy/.
[root@localhost ~]# cp /usr/local/etc/haproxy/haproxy.cfg /docker/btrfs/subvolumes/a57fb85ecf435baab5bc2ceafc70ee00527f6b379dc0c9366c748f1563332376/usr/local/etc/haproxy/.
[root@localhost ~]# cp /usr/local/etc/haproxy/haproxy.cfg /docker/btrfs/subvolumes/f0e08f7411c330363784c15ae4633fe7f14ed6fabf2dc5ffcd3fac1559cb2861/usr/local/etc/haproxy/.
[root@localhost ~]# docker run -it --rm --name haproxy-syntax-check haproxy:1.5 haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -c -f /usr/local/etc/haproxy/haproxy.cfg -Ds
[ALERT] 104/133221 (6) : parsing [/usr/local/etc/haproxy/haproxy.cfg:5] : cannot find user id for 'haproxy' (0:Success)
[ALERT] 104/133221 (6) : parsing [/usr/local/etc/haproxy/haproxy.cfg:6] : cannot find group id for 'haproxy' (0:Success)
[ALERT] 104/133221 (6) : Error(s) found in configuration file : /usr/local/etc/haproxy/haproxy.cfg
[WARNING] 104/133221 (6) : config : missing timeouts for frontend 'www-http'.
| While not properly invalid, you will certainly encounter various problems
| with such a configuration. To fix this, please ensure that all following
| timeouts are set to a non-zero value: 'client', 'connect', 'server'.
[WARNING] 104/133221 (6) : config : missing timeouts for backend 'apache'.
| While not properly invalid, you will certainly encounter various problems
| with such a configuration. To fix this, please ensure that all following
| timeouts are set to a non-zero value: 'client', 'connect', 'server'.
[ALERT] 104/133221 (6) : Fatal errors found in configuration.
haproxy-systemd-wrapper: exit, haproxy RC=256

La suite au prochain épisode ... mais la nouvelle partition nous a permis de régler le premier gros problème. Maintenant il va falloir faire un fichier propre de configuration avec des conteneurs propres. Et il va falloir bien faire **la différence entre fichier local et fichier dans un conteneur**.

Avant de ce quitter un petit df afin de voir la taille utilisée :
[root@localhost ~]# df -h
Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur
devtmpfs 353M 0 353M 0% /dev
tmpfs 370M 0 370M 0% /dev/shm
tmpfs 370M 5,0M 365M 2% /run
tmpfs 370M 0 370M 0% /sys/fs/cgroup
/dev/sda2 4,1G 2,0G 2,2G 47% /
/dev/sda1 17G 174M 15G 2% /docker
tmpfs 74M 0 74M 0% /run/user/0

J'ai surement pas mis assez de place dans la partition / .... il va pas falloir compiler ;) .

En fait rien ne fonctionne car je n'ai pas respecter l'ordre, dans un premier temps il faut faire un **Dockerfile** c'est ce fichier qui va créer la configuration et les utilisateurs dans l'environnement. Ensuite il faudra faire un **build** de ce fichier Dockerfile.
[root@localhost ~]# docker **build** -t my-haproxy .
Sending build context to Docker daemon 13.82 kB
Step 1 : FROM haproxy:1.5
---> 011e001101c0
Step 2 : COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
---> 80428a4d0c7a
Removing intermediate container a32307b4902e
Successfully built 80428a4d0c7a
[root@localhost ~]# cat Dockerfile
FROM haproxy:1.5
COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

Ensuite on peut indiquer qui est l'auteur et ajouter des utilisateurs ...
[root@localhost ~]# docker build -t my-haproxy .
Sending build context to Docker daemon 13.82 kB
Step 1 : FROM haproxy:1.5
---> 011e001101c0
Step 2 : MAINTAINER Toto <toto@cyber-neurones.org>
---> Running in 581f5cb3d821
---> 2afe3bb2588d
Removing intermediate container 581f5cb3d821
Step 3 : COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
---> 37b23cd1bd7f
Removing intermediate container 40bf1ce4608a
Step 4 : RUN groupadd -r haproxy && useradd -r -g haproxy haproxy
---> Running in 06b262433902
---> 73e7842bb76b
Removing intermediate container 06b262433902
Successfully built 73e7842bb76b
[root@localhost ~]# cat Dockerfile
FROM haproxy:1.5
MAINTAINER Toto <toto@cyber-neurones.org>
COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
RUN groupadd -r haproxy && useradd -r -g haproxy haproxy

Il faut penser à faire ceci si vous avez fait n'importe quoi avant
[root@localhost ~]# docker rmi $(docker images -q)

L'autre solution c'est l'utilisation de la commande -v à la place de -f (par exemple : -v /usr/local/etc/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg c.a.d. from:to )

Et un dernier pour finir encore un peu plus complexe :
FROM haproxy:1.5
MAINTAINER Toto <toto@cyber-neurones.org>
COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
ENV HAPROXY_USER haproxy
RUN groupadd --system ${HAPROXY_USER} && \
useradd --system --gid ${HAPROXY_USER} ${HAPROXY_USER} && \
mkdir --parents /var/lib/${HAPROXY_USER} && \
chown -R ${HAPROXY_USER}:${HAPROXY_USER} /var/lib/${HAPROXY_USER}
CMD ["haproxy", "-db", "-f", "/usr/local/etc/haproxy/haproxy.cfg"]

Pour la suite je vais aussi ajouter la commande netstat afin de pouvoir vérifier si le port est bien en écoute.
[root@localhost ~]# yum install **net-tools**
[root@localhost ~]# netstat -at
Connexions Internet actives (serveurs et établies)
Proto Recv-Q Send-Q Adresse locale Adresse distante Etat
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdoma:ssh 192.168.1.10:62127 ESTABLISHED
tcp6 0 0 [::]:ssh [::]:* LISTEN
tcp6 0 0 localhost:smtp [::]:* LISTEN

Je vais aussi mettre la commande lsof afin de mieux étudier le système .
[root@localhost ~]# yum install **lsof
**