Docker : le septième pas.

1651 x served & 625 x viewed

Attention ceci est mon brouillon avant de faire une belle documentation sur Docker (il y a à boire et à manger). Sachant que celui-ci c’est 100% échec 🙁 .

J’ai repoussé plusieurs fois l’installation de HAproxy maintenant je vais devoir le faire. Pour cela je vais m’appuyer sur mon server4.c qui va recevoir la charge du HAproxy. Je vais lancer 4 server4 qui vont écouter sur 4 ports différents (8080/tcp, 8081/tcp, 8082/tcp, 8083/tcp) .

[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
08c524d398af my-server4 "/sbin/server4" 49 minutes ago Up 49 minutes 0.0.0.0:80->80/tcp my-server4.1
2fc533c55725 postgres "/docker-entrypoint.s" 10 hours ago Up 10 hours 0.0.0.0:5432->5432/tcp postgres2
[root@localhost ~]# docker stop 08c524d398af
08c524d398af
[root@localhost ~]# docker run -p 8080:80 --link postgres2:postgres2 --name my-server4-1 -d my-server4
eacf3e4bc897f94c6cf5feee71194637c44708f85aaa497531e8f2d2ea6d2e0f
[root@localhost ~]# docker run -p 8081:80 --link postgres2:postgres2 --name my-server4-2 -d my-server4
a75937eb980dc24e260f1e7cfeb3611e3a93c339a0ff68202e4c483c0f768301
[root@localhost ~]# docker run -p 8082:80 --link postgres2:postgres2 --name my-server4-3 -d my-server4
fce6865343f1bf46d9089fb005624955f550d078d583711a23f85748e034421b
[root@localhost ~]# docker run -p 8083:80 --link postgres2:postgres2 --name my-server4-4 -d my-server4
78f6bc54152e1c5d7a8608a03f2a1937ec19ba05535f725445b203e42f3c6430
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
78f6bc54152e my-server4 "/sbin/server4" 4 seconds ago Up 3 seconds 0.0.0.0:8083->80/tcp my-server4-4
fce6865343f1 my-server4 "/sbin/server4" 14 seconds ago Up 14 seconds 0.0.0.0:8082->80/tcp my-server4-3
a75937eb980d my-server4 "/sbin/server4" 24 seconds ago Up 24 seconds 0.0.0.0:8081->80/tcp my-server4-2
eacf3e4bc897 my-server4 "/sbin/server4" 35 seconds ago Up 34 seconds 0.0.0.0:8080->80/tcp my-server4-1
2fc533c55725 postgres "/docker-entrypoint.s" 10 hours ago Up 10 hours 0.0.0.0:5432->5432/tcp postgres2
[root@localhost ~]# df
Sys. de fichiers blocs de 1K Utilisé Disponible Uti% Monté sur
devtmpfs              360876       0     360876   0% /dev
tmpfs                 378400       0     378400   0% /dev/shm
tmpfs                 378400   10016     368384   3% /run
tmpfs                 378400       0     378400   0% /sys/fs/cgroup
/dev/sda2            4278272 2122616    2155656  50% /
/dev/sda1           17825792 2027556   13935068  13% /docker
tmpfs                  75680       0      75680   0% /run/user/0

J’ai maintenant tous mes serveurs server4 en place. On va partir sur cette configuration de HAProxy.

[root@localhost ~]# cat haproxy.cfg 
frontend docker-haproxy
        bind 127.0.0.1:80
        mode tcp
        log global
        option tcplog
        timeout client 3600s
        backlog 4096
        maxconn 50000
        default_backend dockers-server4

backend dockers-server4
        mode  tcp
        option log-health-checks
        option redispatch
        option tcplog
        balance roundrobin
        server server1 127.0.0.1:8080
        server server2 127.0.0.1:8081
	server server3 127.0.0.1:8082
	server server4 127.0.0.1:8083
        timeout connect 2s
        timeout queue 6s
        timeout server 3600s

Après le fichier de configuration, on doit faire le Dockerfile, puis le build.

[root@localhost ~]# cat Dockerfile
FROM haproxy:1.5
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

[root@localhost ~]# docker build -t my-haproxy .
Sending build context to Docker daemon   130 kB
Step 1 : FROM haproxy:1.5
1.5: Pulling from library/haproxy
efd26ecc9548: Already exists 
a3ed95caeb02: Pull complete 
545a1e51c226: Pull complete 
4f8fd706ca7d: Pull complete 
c7652a33f7e1: Pull complete 
Digest: sha256:8970d415c69e563a2729b2d1d123f743daef86757b965686f12b1f840cab13da
Status: Downloaded newer image for haproxy:1.5
 ---> 011e001101c0
Step 2 : COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
 ---> d22222a2d97a
Removing intermediate container da366b06caf8
Successfully built d22222a2d97a
[root@localhost ~]# docker run -p 80:80 -d --name mon-haproxy-server4 my-haproxy
dcfe4d416951e10592ef2025e569c742f0853e2026713c0a65edb37b2f5b5c1f
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
dcfe4d416951        my-haproxy          "/docker-entrypoint.s"   5 seconds ago       Up 4 seconds        0.0.0.0:80->80/tcp       mon-haproxy-server4
78f6bc54152e        my-server4          "/sbin/server4"          46 minutes ago      Up 46 minutes       0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          46 minutes ago      Up 46 minutes       0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          46 minutes ago      Up 46 minutes       0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          47 minutes ago      Up 47 minutes       0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   11 hours ago        Up 11 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.

J’ai du mal comprendre, ou alors le HAProxy n’est pas lancé. Je vais donc commencé par tester le fichier de configuration.

[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] 105/062529 (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 ~]# docker run -it --rm --name haproxy-syntax-check haproxy:1.5 haproxy -c -f ./haproxy.cfg
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -c -f ./haproxy.cfg -Ds 
[ALERT] 105/062620 (6) : Could not open configuration file ./haproxy.cfg : No such file or directory
haproxy-systemd-wrapper: exit, haproxy RC=256
[root@localhost ~]# docker run -it --rm --name haproxy-syntax-check haproxy:1.5 haproxy -c -f haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -c -f haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg -Ds 
[ALERT] 105/062638 (6) : Could not open configuration file haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg : No such file or directory
haproxy-systemd-wrapper: exit, haproxy RC=256
[root@localhost ~]# locate haproxy.cfg
/docker/btrfs/subvolumes/5ca530873be0b9de105bf5ed3d05288a32c39d376d07c48c02a7182f2a58c3be/usr/local/etc/haproxy/haproxy.cfg
/docker/btrfs/subvolumes/9e5cabf00aa9cbc5c34e864f828f6e4e125f6a200c35781b746a4078b4506d00/usr/local/etc/haproxy/haproxy.cfg
/docker/btrfs/subvolumes/9e5cabf00aa9cbc5c34e864f828f6e4e125f6a200c35781b746a4078b4506d00-init/usr/local/etc/haproxy/haproxy.cfg
/docker/btrfs/subvolumes/e541302d054ad41122dfc8f8537da225d57db270e750f23cc34e9ff29298d15b/usr/local/etc/haproxy/haproxy.cfg
/docker/btrfs/subvolumes/e541302d054ad41122dfc8f8537da225d57db270e750f23cc34e9ff29298d15b-init/usr/local/etc/haproxy/haproxy.cfg
/root/haproxy.cfg
/usr/local/etc/haproxy/haproxy.cfg

J’ai l’impression d’avoir déjà eu ce problème… en fait le fichier est en local mais il n’est pas dans le container. Pourtant dans le Dockerfile je demande bien la copie. Je vais donc m’en sortir avec la commande -v mais cela ne me plait pas 🙁 , j’ai du louper un épisode.

[root@localhost ~]# docker run -it --rm --name haproxy-syntax-check haproxy:1.5 haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg -v ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -c -f /usr/local/etc/haproxy/haproxy.cfg -v ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro -Ds 
HA-Proxy version 1.5.17 2016/04/13
Copyright 2000-2016 Willy Tarreau <willy@haproxy.org>

haproxy-systemd-wrapper: exit, haproxy RC=0

Maintenant il me faut voir les logs de HAproxy, pour cela je vais devoir refaire le fichier de configuration.
Je recommande et j’en profile pour signaler le port 80 dans le Dockerfile :

[root@localhost ~]# cat Dockerfile
FROM haproxy:1.5
COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
EXPOSE 80
[root@localhost ~]# cat haproxy.cfg 
frontend docker-haproxy
        bind 127.0.0.1:80
        mode tcp
	log /dev/log local2
        option tcplog
        timeout client 3600s
        backlog 4096
        maxconn 50000
        default_backend dockers-server4

backend dockers-server4
        mode  tcp
        option log-health-checks
        option redispatch
        option tcplog
        balance roundrobin
        server server1 127.0.0.1:8080
        server server2 127.0.0.1:8081
	server server3 127.0.0.1:8082
	server server4 127.0.0.1:8083
        timeout connect 2s
        timeout queue 6s
        timeout server 3600s
[root@localhost ~]# cat Dockerfile
FROM haproxy:1.5
COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
EXPOSE 80
[root@localhost ~]# docker run -d -p 80:80 --name mon-haproxy--v2 my-haproxy-v2 -v /dev/log:/dev/log
64ccfb0eaec9681e52150830a38b52b0d4dcff91c6a66ab3c45ee4b18d40064d
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   11 hours ago        Up 11 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# telnet 127.0.0.1 80
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   11 hours ago        Up 11 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# docker run -d -p 80:80 --name mon-haproxy---v2 my-haproxy-v2 
4147ceb13680a33e0c3e8b2f8e8d8f10a195fead10c10d7a1ea21e208e103a59
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
4147ceb13680        my-haproxy-v2       "/docker-entrypoint.s"   2 seconds ago       Up 1 seconds        0.0.0.0:80->80/tcp       mon-haproxy---v2
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   11 hours ago        Up 11 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# docker logs 4147ceb13680
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -f /usr/local/etc/haproxy/haproxy.cfg -Ds 
[ALERT] 105/065612 (6) : sendto logger #1 failed: No such file or directory (errno=2)

C’est l’échec quand je lance avec l’option -v . Je vais donc apporter quelques modifications.

[root@localhost ~]# cat haproxy.cfg 
global
    	log 127.0.0.1   local0
    	log 127.0.0.1   local1 notice
    	debug
    	stats timeout 30s
    	maxconn 1024

frontend docker-haproxy
        bind *:80
        mode tcp
        option tcplog
        timeout connect 50
        timeout client 50
        timeout server 50
        default_backend dockers-server4

backend dockers-server4
        mode  tcp
        option log-health-checks
        option redispatch
        option tcplog
        balance roundrobin
        server server1 127.0.0.1:8080
        server server2 127.0.0.1:8081
	server server3 127.0.0.1:8082
	server server4 127.0.0.1:8083
        timeout connect 10s
        timeout queue 10s

[root@localhost ~]# docker build -t my-haproxy-v3 .
Sending build context to Docker daemon   130 kB
Step 1 : FROM haproxy:1.5
 ---> 011e001101c0
Step 2 : COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
 ---> ca38be6976c3
Removing intermediate container fdeadde5c6fe
Step 3 : EXPOSE 80
 ---> Running in 31e17c430e2e
 ---> 4285c0689948
Removing intermediate container 31e17c430e2e
Successfully built 4285c0689948
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
4147ceb13680        my-haproxy-v2       "/docker-entrypoint.s"   9 minutes ago       Up 9 minutes        0.0.0.0:80->80/tcp       mon-haproxy---v2
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   11 hours ago        Up 11 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# docker stop 4147ceb13680
4147ceb13680
[root@localhost ~]# docker run -d -p 80:80 --name mon-haproxy-v3 my-haproxy-v3 
53d881348b237a33324da593a070f566ef9af1fffeceb01ffab56f4c270c7268
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
53d881348b23        my-haproxy-v3       "/docker-entrypoint.s"   8 seconds ago       Up 8 seconds        0.0.0.0:80->80/tcp       mon-haproxy-v3
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   11 hours ago        Up 11 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.
[root@localhost ~]# docker logs 53d881348b23
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -f /usr/local/etc/haproxy/haproxy.cfg -Ds 
[WARNING] 105/070623 (6) : parsing [/usr/local/etc/haproxy/haproxy.cfg:12] : 'timeout connect' will be ignored because frontend 'docker-haproxy' has no backend capability
[WARNING] 105/070623 (6) : parsing [/usr/local/etc/haproxy/haproxy.cfg:14] : 'timeout server' will be ignored because frontend 'docker-haproxy' has no backend capability
[WARNING] 105/070623 (6) : config : frontend 'GLOBAL' has no 'bind' directive. Please declare it as a backend if this was intended.
[WARNING] 105/070623 (6) : config : log format ignored for frontend 'docker-haproxy' since it has no log address.
[WARNING] 105/070623 (6) : config : missing timeouts for backend 'dockers-server4'.
   | 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'.

Un nouveau test :

[root@localhost ~]# cat haproxy.cfg 
global
    	log 127.0.0.1   local0
    	log 127.0.0.1   local1 notice
    	debug
    	stats timeout 30s
    	maxconn 1024

frontend docker-haproxy
        bind 127.0.0.1:80 
        mode tcp
        option tcplog
        timeout client 50
        default_backend dockers-server4

backend dockers-server4
        mode  tcp
        option tcplog
        balance roundrobin
        server server1 127.0.0.1:8080
        server server2 127.0.0.1:8081
	server server3 127.0.0.1:8082
	server server4 127.0.0.1:8083
        timeout connect 10s
        timeout queue 10s

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
53d881348b23        my-haproxy-v3       "/docker-entrypoint.s"   5 minutes ago       Up 5 minutes        0.0.0.0:80->80/tcp       mon-haproxy-v3
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   11 hours ago        Up 11 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# docker stop 53d881348b23
53d881348b23
[root@localhost ~]# docker build -t my-haproxy-v4 .
Sending build context to Docker daemon   130 kB
Step 1 : FROM haproxy:1.5
 ---> 011e001101c0
Step 2 : COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
 ---> 1d1b5ce9efa3
Removing intermediate container 8552d9644f69
Step 3 : EXPOSE 80
 ---> Running in 74b056413e7e
 ---> a81f74591597
Removing intermediate container 74b056413e7e
Successfully built a81f74591597
[root@localhost ~]# docker run -d -p 80:80 --name mon-haproxy-v4 my-haproxy-v4 
8067ac57b6240b376d6d783d61e5345e0e3a4d0296a4b91ea0740eadf859257d
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
8067ac57b624        my-haproxy-v4       "/docker-entrypoint.s"   3 seconds ago       Up 3 seconds        0.0.0.0:80->80/tcp       mon-haproxy-v4
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   11 hours ago        Up 11 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# docker logs 8067ac57b624
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -f /usr/local/etc/haproxy/haproxy.cfg -Ds 
[WARNING] 105/071212 (6) : config : frontend 'GLOBAL' has no 'bind' directive. Please declare it as a backend if this was intended.
[WARNING] 105/071212 (6) : config : log format ignored for frontend 'docker-haproxy' since it has no log address.
[WARNING] 105/071212 (6) : config : missing timeouts for backend 'dockers-server4'.
   | 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'.

Je vais prendre une autre syntaxe pour le HAproxy :

[root@localhost ~]# cat haproxy.cfg 
global
        debug
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice

defaults
        log global
        mode    tcp
        timeout connect 5000
        timeout client 5000
        timeout server 5000

listen http :80
        mode tcp
        balance roundrobin
        server server1 127.0.0.1:8080 check
        server server2 127.0.0.1:8081 check
        server server3 127.0.0.1:8082 check
        server server4 127.0.0.1:8083 check

[root@localhost ~]# docker build -t my-haproxy-v5 .
Sending build context to Docker daemon 129.5 kB
Step 1 : FROM haproxy:1.5
 ---> 011e001101c0
Step 2 : COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
 ---> f0e298916916
Removing intermediate container bde8ad053d88
Step 3 : EXPOSE 80
 ---> Running in 91e7630a2f2b
 ---> 33fd422d7c01
Removing intermediate container 91e7630a2f2b
Successfully built 33fd422d7c01
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
8067ac57b624        my-haproxy-v4       "/docker-entrypoint.s"   7 minutes ago       Up 7 minutes        0.0.0.0:80->80/tcp       mon-haproxy-v4
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   11 hours ago        Up 11 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# docker stop 8067ac57b624
8067ac57b624
[root@localhost ~]# docker run -d -p 80:80 --name mon-haproxy-v5 my-haproxy-v5 
36dc1d1c8699fd628909c3c4e064991b8ff011ffb42620066374eb14c5b5617a
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
36dc1d1c8699        my-haproxy-v5       "/docker-entrypoint.s"   6 seconds ago       Up 6 seconds        0.0.0.0:80->80/tcp       mon-haproxy-v5
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   11 hours ago        Up 11 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# docker logs 36dc1d1c8699
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -f /usr/local/etc/haproxy/haproxy.cfg -Ds 
[root@localhost ~]# telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.

Je n’ai plus de Warning mais ce n’est pas pour autant que cela fonctionne 🙁 . Je tourne en rond ..

[root@localhost ~]# cat haproxy.cfg 
global
        debug
	log /dev/log local2

defaults
        log global
        mode    tcp
        timeout connect 5000
        timeout client 5000
        timeout server 5000

listen http :80
        mode tcp
        balance roundrobin
        server server1 127.0.0.1:8080 check
        server server2 127.0.0.1:8081 check
        server server3 127.0.0.1:8082 check
        server server4 127.0.0.1:8083 check
[root@localhost ~]# docker build -t my-haproxy-v6 .
Sending build context to Docker daemon 129.5 kB
Step 1 : FROM haproxy:1.5
 ---> 011e001101c0
Step 2 : COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
 ---> 39b1812d0aa2
Removing intermediate container 51a78465fe7c
Step 3 : EXPOSE 80
 ---> Running in c29ce6db7d20
 ---> 7aa5797d1258
Removing intermediate container c29ce6db7d20
Successfully built 7aa5797d1258
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
36dc1d1c8699        my-haproxy-v5       "/docker-entrypoint.s"   10 minutes ago      Up 10 minutes       0.0.0.0:80->80/tcp       mon-haproxy-v5
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   12 hours ago        Up 12 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# docker stop 36dc1d1c8699
36dc1d1c8699
[root@localhost ~]# docker run -d -v /dev/logs:/dev/logs -p 80:80 --name mon-haproxy-v6 my-haproxy-v6
58cf965e6ccf1d538c736493d6bd1b6829bfb1bb345aa470e60e9290ece54d7d
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
58cf965e6ccf        my-haproxy-v6       "/docker-entrypoint.s"   4 seconds ago       Up 3 seconds        0.0.0.0:80->80/tcp       mon-haproxy-v6
78f6bc54152e        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   12 hours ago        Up 12 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.
[root@localhost ~]# docker logs 58cf965e6ccf
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -f /usr/local/etc/haproxy/haproxy.cfg -Ds 
[ALERT] 105/073135 (6) : sendto logger #1 failed: No such file or directory (errno=2)

Je vais essayer de mettre tous les fichiers en local ..

[root@localhost ~]# mkdir /docker/mon-haxproxy
[root@localhost ~]# mkdir /docker/mon-haxproxy/log
[root@localhost ~]# mkdir /docker/mon-haxproxy/run
[root@localhost ~]# mkdir /docker/mon-haxproxy/lib
[root@localhost ~]# cat haproxy.cfg 
global
        debug
	log 127.0.0.1 local2

defaults
        log global
        mode    tcp
        timeout connect 5000
        timeout client 5000
        timeout server 5000

listen http :80
        mode tcp
        balance roundrobin
        server server1 127.0.0.1:8080 check
        server server2 127.0.0.1:8081 check
        server server3 127.0.0.1:8082 check
        server server4 127.0.0.1:8083 check

[root@localhost ~]# docker build -t my-haproxy-v7 .
Sending build context to Docker daemon 129.5 kB
Step 1 : FROM haproxy:1.5
 ---> 011e001101c0
Step 2 : COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
 ---> de4df4115d0d
Removing intermediate container 865acfb251bb
Step 3 : EXPOSE 80
 ---> Running in 90bcecb3e4a2
 ---> b7437c93d09a
Removing intermediate container 90bcecb3e4a2
Successfully built b7437c93d09a
[root@localhost ~]# docker run -d -v /dev/logs:/dev/logs -v /docker/mon-haxproxy/log:/var/log -v /docker/mon-haxproxy/lib:/var/lib/haproxy -v /docker/mon-haxproxy/run:/run  -p 80:80 --name mon-haproxy-v7 my-haproxy-v7
936562384c2f2a5d688dc3888bf9fb292b07f4966d7ee84d37315cee9861cf19
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
936562384c2f        my-haproxy-v7       "/docker-entrypoint.s"   4 seconds ago       Up 3 seconds        0.0.0.0:80->80/tcp       mon-haproxy-v7
78f6bc54152e        my-server4          "/sbin/server4"          2 hours ago         Up 2 hours          0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          2 hours ago         Up 2 hours          0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          2 hours ago         Up 2 hours          0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          2 hours ago         Up 2 hours          0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   12 hours ago        Up 12 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.
[root@localhost ~]# docker logs 936562384c2f
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -f /usr/local/etc/haproxy/haproxy.cfg -Ds 
[root@localhost ~]# vi /docker/mon-haxproxy/
lib/ log/ run/  
[root@localhost ~]# ls -l /docker/mon-haxproxy/*/*
-rw-r--r-- 1 root root 2 15 avril 08:54 /docker/mon-haxproxy/run/haproxy.pid

Je commence à comprendre pourquoi je gardais HAproxy pour la fin. Un dernier test …

[root@localhost ~]# cat /proc/sys/net/unix/max_dgram_qlen
10
[root@localhost ~]# echo "1000" > /proc/sys/net/unix/max_dgram_qlen
[root@localhost ~]# cat /proc/sys/net/unix/max_dgram_qlen
1000
[root@localhost ~]# cat haproxy.cfg 
global
        debug
	log /dev/stdout local0

defaults
        log global
        mode    tcp
        timeout connect 5000
        timeout client 5000
        timeout server 5000

listen http :80
        mode tcp
        balance roundrobin
        server server1 127.0.0.1:8080 check
        server server2 127.0.0.1:8081 check
        server server3 127.0.0.1:8082 check
        server server4 127.0.0.1:8083 check
...
[root@localhost ~]# docker logs e0c59b830250
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -f /usr/local/etc/haproxy/haproxy.cfg -Ds 
[ALERT] 105/081317 (6) : sendto logger #1 failed: Connection refused (errno=111)

Pas si facile d’avoir les logs et de comprendre le problème. Je pense que je vais voir si Nginx est aussi simple 😉 .

Oups, je viens de réaliser que j’avais fait la même erreur que hier ! Je n’ai pas raisonné en terme de container.

 

[root@localhost ~]# cat haproxy.cfg 
global
        debug
	log 127.0.0.1 local0
	log 127.0.0.1 local2 notice

defaults
        log global
        mode    tcp
        timeout connect 5000
        timeout client 5000
        timeout server 5000

listen http :80
        mode tcp
        balance roundrobin
        server server1 server1:8080 check
        server server2 server2:8081 check
        server server3 server3:8082 check
        server server4 server3:8083 check

[root@localhost ~]# docker build -t my-haproxy-v10 .
Sending build context to Docker daemon 129.5 kB
Step 1 : FROM haproxy:1.5
 ---> 011e001101c0
Step 2 : COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
 ---> 846ccc0764d9
Removing intermediate container 92573d92d290
Step 3 : EXPOSE 80
 ---> Running in 1dd245964801
 ---> 3405838fec48
Removing intermediate container 1dd245964801
Successfully built 3405838fec48
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
e0c59b830250        my-haproxy-v8       "/docker-entrypoint.s"   28 minutes ago      Up 28 minutes       0.0.0.0:80->80/tcp       mon-haproxy-v8.b
78f6bc54152e        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   13 hours ago        Up 13 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# docker stop e0c59b830250
e0c59b830250
[root@localhost ~]# docker run -d --link my-server4-1 --link my-server4-2 --link my-server4-3 --link my-server4-4 -p 80:80 --name mon-haproxy-v10 my-haproxy-v10
6f6208ac6a76e77de937eac6085c1d715b9775852dcf1e7a0ae43d5293f80e7d
[root@localhost ~]# telnet 127.0.0.1 80
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
78f6bc54152e        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   13 hours ago        Up 13 hours         0.0.0.0:5432->5432/tcp   postgres2

Il ne se lance pas …

[root@localhost ~]# docker logs 6f6208ac6a76e77de937eac6085c1d715b9775852dcf1e7a0ae43d5293f80e7d
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -f /usr/local/etc/haproxy/haproxy.cfg -Ds 
[ALERT] 105/084348 (6) : parsing [/usr/local/etc/haproxy/haproxy.cfg:16] : 'server server1' : invalid address: 'server1' in 'server1:8080'

[ALERT] 105/084348 (6) : parsing [/usr/local/etc/haproxy/haproxy.cfg:17] : 'server server2' : invalid address: 'server2' in 'server2:8081'

[ALERT] 105/084348 (6) : parsing [/usr/local/etc/haproxy/haproxy.cfg:18] : 'server server3' : invalid address: 'server3' in 'server3:8082'

[ALERT] 105/084348 (6) : parsing [/usr/local/etc/haproxy/haproxy.cfg:19] : 'server server4' : invalid address: 'server3' in 'server3:8083'

[ALERT] 105/084348 (6) : Error(s) found in configuration file : /usr/local/etc/haproxy/haproxy.cfg
[ALERT] 105/084348 (6) : Fatal errors found in configuration.
haproxy-systemd-wrapper: exit, haproxy RC=256

Voici la commande inspect qui va nous permettre de savoir ce qu’il y a dans /etc/hosts :

[root@localhost ~]# docker inspect 6f6208ac6a76e77de937eac6085c1d715b9775852dcf1e7a0ae43d5293f80e7d
[
    {
        "Id": "6f6208ac6a76e77de937eac6085c1d715b9775852dcf1e7a0ae43d5293f80e7d",
        "Created": "2016-04-15T08:43:48.407165954Z",
        "Path": "/docker-entrypoint.sh",
        "Args": [
            "haproxy",
            "-f",
            "/usr/local/etc/haproxy/haproxy.cfg"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2016-04-15T08:43:48.569704841Z",
            "FinishedAt": "2016-04-15T08:43:48.747782328Z"
        },
        "Image": "sha256:3405838fec481ca60b848eb230c4b1af27e74eb729494329bad6209c1cc79371",
        "ResolvConfPath": "/docker/containers/6f6208ac6a76e77de937eac6085c1d715b9775852dcf1e7a0ae43d5293f80e7d/resolv.conf",
        "HostnamePath": "/docker/containers/6f6208ac6a76e77de937eac6085c1d715b9775852dcf1e7a0ae43d5293f80e7d/hostname",
        "HostsPath": "/docker/containers/6f6208ac6a76e77de937eac6085c1d715b9775852dcf1e7a0ae43d5293f80e7d/hosts",
        "LogPath": "/docker/containers/6f6208ac6a76e77de937eac6085c1d715b9775852dcf1e7a0ae43d5293f80e7d/6f6208ac6a76e77de937eac6085c1d715b9775852dcf1e7a0ae43d5293f80e7d-json.log",
        "Name": "/mon-haproxy-v10",
        "RestartCount": 0,
        "Driver": "btrfs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": [
                "/my-server4-2:/mon-haproxy-v10/my-server4-2",
                "/my-server4-3:/mon-haproxy-v10/my-server4-3",
                "/my-server4-4:/mon-haproxy-v10/my-server4-4",
                "/my-server4-1:/mon-haproxy-v10/my-server4-1"
            ],
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "StorageOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "BlkioIOps": 0,
            "BlkioBps": 0,
            "SandboxSize": 0
        },
        "GraphDriver": {
            "Name": "btrfs",
            "Data": null
        },
        "Mounts": [],
        "Config": {
            "Hostname": "6f6208ac6a76",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "HAPROXY_MAJOR=1.5",
                "HAPROXY_VERSION=1.5.17",
                "HAPROXY_MD5=98340e8ba4eeb376d301adc8f235b043"
            ],
            "Cmd": [
                "haproxy",
                "-f",
                "/usr/local/etc/haproxy/haproxy.cfg"
            ],
            "Image": "my-haproxy-v10",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "eccd857f9928a21e6823e3865eb63e573f759f391492a9619ac8acde9e65e475",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": null,
            "SandboxKey": "/var/run/docker/netns/eccd857f9928",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "55fda48e57b67e66f6c0a55a123956056b9eb2c9dec518dbab92f946bc52a4c6",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": ""
                }
            }
        }
    }
]
[root@localhost ~]# cat /docker/containers/6f6208ac6a76e77de937eac6085c1d715b9775852dcf1e7a0ae43d5293f80e7d/hosts 
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
172.17.0.3	my-server4-1 eacf3e4bc897
172.17.0.4	my-server4-2 a75937eb980d
172.17.0.5	my-server4-3 fce6865343f1
172.17.0.6	my-server4-4 78f6bc54152e
172.17.0.7	6f6208ac6a76

Effectivement j’ai mis n’importe quoi, mais je voulais tester la commande inspect.

[root@localhost ~]# cat haproxy.cfg 
global
        debug
	log 127.0.0.1 local0
	log 127.0.0.1 local2 notice

defaults
        log global
        mode    tcp
        timeout connect 5000
        timeout client 5000
        timeout server 5000

listen http :80
        mode tcp
        balance roundrobin
        server server1 my-server4-1:8080 check
        server server2 my-server4-2:8081 check
        server server3 my-server4-3:8082 check
        server server4 my-server4-4:8083 check

[root@localhost ~]# docker build -t my-haproxy-v11 .
Sending build context to Docker daemon 129.5 kB
Step 1 : FROM haproxy:1.5
 ---> 011e001101c0
Step 2 : COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
 ---> 04fbe6ce4329
Removing intermediate container 6b45d6c95aa7
Step 3 : EXPOSE 80
 ---> Running in a4b36ea1b4cc
 ---> d7608471e969
Removing intermediate container a4b36ea1b4cc
Successfully built d7608471e969
[root@localhost ~]# docker run -d --link my-server4-1 --link my-server4-2 --link my-server4-3 --link my-server4-4 -p 80:80 --name mon-haproxy-v11 my-haproxy-v11
818819b23e72b2672b55dba19d22e36dd830ce05c1b1f43acce50bc4122ef10b
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
818819b23e72        my-haproxy-v11      "/docker-entrypoint.s"   3 seconds ago       Up 3 seconds        0.0.0.0:80->80/tcp       mon-haproxy-v11
78f6bc54152e        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8083->80/tcp     my-server4-4
fce6865343f1        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8082->80/tcp     my-server4-3
a75937eb980d        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8081->80/tcp     my-server4-2
eacf3e4bc897        my-server4          "/sbin/server4"          3 hours ago         Up 3 hours          0.0.0.0:8080->80/tcp     my-server4-1
2fc533c55725        postgres            "/docker-entrypoint.s"   13 hours ago        Up 13 hours         0.0.0.0:5432->5432/tcp   postgres2
[root@localhost ~]# telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.
[root@localhost ~]# docker logs 818819b23e72
haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -p /run/haproxy.pid -f /usr/local/etc/haproxy/haproxy.cfg -Ds 

Cette fois je pense que j’attaque les bons containers par contre cela ne marche pas et j’ai toujours aucun logs

Misère.

J’ai essayé de supprimer le check mais cela ne fonctionne toujours pas.

[root@localhost ~]# cat haproxy.cfg 
global
        debug
	log 127.0.0.1 local0
	log 127.0.0.1 local2 notice

defaults
        log global
        mode    tcp
        timeout connect 5000
        timeout client 5000
        timeout server 5000

listen http :80
        mode tcp
        balance roundrobin
        server server1 my-server4-1:8080 
        server server2 my-server4-2:8081 
        server server3 my-server4-3:8082 
        server server4 my-server4-4:8083 

En suite j’ai changé le format de fichier haproxy.cfg, mais sans succès.

[root@localhost ~]# cat haproxy.cfg 
global
    maxconn 400

defaults
    log global
    mode    tcp
    option  tcplog
    option  dontlognull
    retries 4
    maxconn 200
    timeout connect  5000
    timeout client  50000
    timeout server  50000

frontend http-in
    bind *:80
    log 127.0.0.1 local0	
    default_backend serveur

backend serveur
        mode tcp
        balance roundrobin
        server server1 my-server4-1:8080
        server server2 my-server4-2:8081
        server server3 my-server4-3:8082
        server server4 my-server4-4:8083

Le problème se sont les logs, débugger sans logs c’est pas possible.

1 réflexion sur « Docker : le septième pas. »

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Time limit is exhausted. Please reload CAPTCHA.