---
# System prepended metadata

title: fichier docker-compose.yml

---


#### Dossier ./web pour contenu web
```
./web/index.php #test serv web
 <?php
  echo '<h1>Bienvenue!<h1>';
	phpinfo();
?>
```


# fichier docker-compose.yml


```
version: '3.8'

services:

    portainer:
        image: portainer/portainer-ce:latest
        restart: always
        volumes:
            - portainer_data:/data
            - /var/run/docker.sock:/var/run/docker.sock
        ports:
            - "9000:9000"
        networks:
            - monreseau

    web:
        container_name: php-apache
        image: php:8.0-apache
        volumes:
           - ./php/src:/var/www/html/
        ports:
           - 8000:80
        networks:
           - monreseau
            
    bdd:
        image: mariadb
        restart: always
        environment:
            MARIADB_ROOT_PASSWORD: rooty
            MYSQL_DATABASE: webBDD
            MYSQL_USER: admin
            MYSQL_PASSWORD: admin
        volumes:
            - ./mysqlVOL:/var/lib/mysql # persistance bdd
        ports:
            - "8889:3306"
        networks:
            - monreseau
            
    adminer_web_bdd:
        image: adminer:latest
        restart: always
        ports:
            - "8080:8080"
        networks:
            - monreseau

    prometheus:
        image: prom/prometheus
        restart: always
        volumes:
                - ./prometheus:/etc/prometheus
        ports:
                - "9090:9090"
        networks:
            - monreseau


    graphana:
        image: grafana/grafana:latest
        container_name: grafana_container
        restart: always
        ports:
            - "3000:3000"
        environment:
            - GF_SECURITY_ADMIN_PASSWORD=password
            - GF_USERS_ALLOW_SIGN_UP=false
        networks:
            - monreseau

volumes:
    portainer_data:

networks:
    monreseau:


    traefik:
        image: "traefik:v2.6"
        container_name: "traefik"
      command:
        - "--api.insecure=true"
        - "--providers.docker=true"
        - "--providers.docker.exposedbydefault=false"
        - "--entrypoints.web.address=:80"
      ports:
        - "60:80"
        - "6060:8080"
      volumes:
        - "/var/run/docker.sock:/var/run/docker.sock:ro"

  whoami:
      image: "traefik/whoami"
      container_name: "simple-service"
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
        - "traefik.http.routers.whoami.entrypoints=web"
    
    
```

            
            
            
            
            
 fichier Dockerfile 

FROM mariadb:latest


FROM httpd:latest
COPY ./src/ /usr/local/apache2/htdocs/



# Traefik

## Enable docker provider and web UI:

### traefik.yml

#### Docker configuration backend
```
providers:
  docker:
    defaultRule: "Host(`{{ trimPrefix `/` .Name }}.docker.localhost`)"
```

#### API and dashboard configuration
```
api:
  insecure: true
```
  
## Start Traefik

```
docker run -d -p 8080:8080 -p 80:80 \
-v $PWD/traefik.yml:/etc/traefik/traefik.yml \
-v /var/run/docker.sock:/var/run/docker.sock \
traefik:v2.5
```

## Start a backend server

`docker run -d --name test traefik/whoami`

## Acces au server a travers traefik avec le nom de domaine "test.docker.localhost"

```
'http://localhost:80/'
$ curl test.docker.localhost
Hostname: 390a880bdfab
IP: 127.0.0.1
IP: 172.17.0.3
GET / HTTP/1.1
Host: test.docker.localhost
User-Agent: curl/7.65.3
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.17.0.1
X-Forwarded-Host: test.docker.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: 7e073cb54211
X-Real-Ip: 172.17.0.1
```


fichier prometheus.yml

global:
    scrap_interval: 30s
    scrap_timeout: 10s
    
rule_file:
    - alert.yml
    
scrape_configs:
    - job_name: services
      metrics_path: /metrics
      static_configs:
          - targets:
              - 'prometheus:9090'
              - 'adresse_ip:9104'