reseau solution
vi haproxy.cfgfrontend http_frontend bind *:80 default_backend http_backendbackend http_backend mode http balance roundrobin server server1 web1:80 check server server2 web2:80 checkdocker network create webdocker network lsNETWORK ID NAME DRIVER SCOPE215762b5f166 bridge bridge locald44bd01134bd host host localcf2a789ecb04 none null local1b7e609de0f2 web bridge localCréer 2 images “nginx1“ et “nginx2“ avec des fichiers index.html spécifiques :
vi web1/DockerfileFROM nginx:1.19-alpineCOPY index.html /usr/share/nginx/htmlvi web1/index.htmlServer ONEdocker build -t nginx1 web1vi web2/DockerfileFROM nginx:1.19-alpineCOPY index.html /usr/share/nginx/htmlvi web2/index.htmlServer TWO TWOdocker build -t nginx2 web2Créer l’image myhaproxy avec de fichier de configuration fourni :
vi myhaproxy/DockerfileFROM haproxy:1.7COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfgvi myhaproxy/haproxy.cfgfrontend http_frontend bind *:80 default_backend http_backendbackend http_backend mode http balance roundrobin server server1 web1:80 check server server2 web2:80 checkdocker build -t myhaproxy myhaproxyLancer les 3 conteneurs :
docker run -d --network=web --name=web1 nginx1docker run -d --network=web --name=web2 nginx2docker run -d --network=web --name=myhaproxy -p 80:80 myhaproxyVérifier le haproxy :
curl localhostServer Onecurl localhostServer Two