Skip to content

Compose

Reprendre l’exercice HPROXY avec docker compose

Terminal window
$ vi docker-compose.yml
Terminal window
services:
myhaproxy:
image: haproxy:1.7
volumes:
- "/home/sadmin/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg"
ports:
- "80:80"
depends_on:
- web1
- web2
networks:
- web
web1:
image: nginx:1.19-alpine
container_name: web1
volumes:
- "/home/sadmin/web1:/usr/share/nginx/html"
networks:
- web
web2:
image: nginx:1.19-alpine
container_name: web2
volumes:
- "/home/sadmin/web2:/usr/share/nginx/html"
networks:
- web
networks:
web:

Lancer le compose

Terminal window
$ docker compose up -d

Reprendre l’exercice producteur/consommateur

Terminal window
$ vi docker-compose.yml
Terminal window
services:
producteur:
image: alpine:3.17
command: ["/bin/sh","-c","while true; do echo `date` : `hostname` >> /mnt/index.html ; sleep 30; done"]
volumes:
- "nfs_web:/mnt"
consommateur:
image: nginx:1.19-alpine
volumes:
- "nfs_web:/usr/share/nginx/html"
ports:
- "80:80"
volumes:
nfs_web:
driver_opts:
type: "nfs"
o: "addr=192.168.98.1"
device: ":/home/shares/user11"

Lancer le compose

Terminal window
$ docker compose up -d