# Exécution containeurisée avec la DB locale

**URL:** <https://community.dokos.io/t/execution-containeurisee-avec-la-db-locale/800>\
**Category:** 🚧 Installation / Administration\
**Created:** [Octobre 24, 2023, 10:26 UTC](https://community.dokos.io/t/execution-containeurisee-avec-la-db-locale/800 "2023-10-24T10:26:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ledruide](https://community.dokos.io/user_avatar/community.dokos.io/ledruide/32/883_2.png) [@ledruide](https://community.dokos.io/u/ledruide)\
**Post date:** [Octobre 24, 2023, 10:26 UTC](https://community.dokos.io/t/execution-containeurisee-avec-la-db-locale/800/1 "2023-10-24T10:26:38Z")

</div>

Bonjour;  
J’essaie de faire fonctionner le docker compose du fichier [https://gitlab.com/dokos/docli/-/raw/develop/compose/dokos.yaml](https://gitlab.com/dokos/docli/-/raw/develop/compose/dokos.yaml) en utilisant la base de données installée en local sur mon serveur (installation mariaDB 15.1 par défaut avec le compte root sans mdp). Mais lorsque je lance le docker compose, il y a un timeout sur la connection à la DB, j’ai dû oublié quelque chose, mais je n’arrive pas à voir quoi… Peut-être dans les commandes «&nbsp;bench set-config …&nbsp;» pour le backend?  
Avez-vous une idée de ce que j’oublie? Merci par avance 🙂  
Voici le fichier compose.yml que j’utilise:

```yaml
version: "3"

name: dodock

x-image: &image
  image: registry.gitlab.com/dokos/dokos

x-depends-on-ready: &depends_on_site_ready
  depends_on:
    configurator:
      condition: service_completed_successfully
    create-site:
      condition: service_completed_successfully

x-restart-on-failure: &restart_on_failure
  deploy:
    restart_policy:
      condition: on-failure

x-backend-defaults: &backend_defaults
  <<: [*depends_on_site_ready, *restart_on_failure, *image]
  volumes:
    - sites:/home/frappe/frappe-bench/sites
    - logs:/home/frappe/frappe-bench/logs

services:
  backend:
    <<: *backend_defaults
    extra_hosts:
      localhost: 172.17.0.1

  configurator:
    <<: *backend_defaults
    depends_on: {}
    deploy:
      restart_policy:
        condition: "no"
    entrypoint: bash -cx
    command:
      - >
        ls -1 apps > sites/apps.txt;
        bench set-config -g db_host $$DB_HOST;
        bench set-config -gp db_port $$DB_PORT;
        bench set-config -g redis_cache "redis://$$REDIS_CACHE";
        bench set-config -g redis_queue "redis://$$REDIS_QUEUE";
        bench set-config -g redis_socketio "redis://$$REDIS_SOCKETIO";
        bench set-config -gp socketio_port $$SOCKETIO_PORT;
    environment:
      DB_HOST: localhost
      DB_PORT: "3306"
      DB_PASSWORD:
      REDIS_CACHE: redis-cache:6379
      REDIS_QUEUE: redis-queue:6379
      REDIS_SOCKETIO: redis-socketio:6379
      SOCKETIO_PORT: "9000"

  create-site:
    <<: *image
    depends_on:
      configurator:
        condition: service_completed_successfully
      redis-cache:
        condition: service_started
      redis-queue:
        condition: service_started
      redis-socketio:
        condition: service_started
    deploy:
      restart_policy:
        condition: "no"
    volumes:
      - sites:/home/frappe/frappe-bench/sites
      - logs:/home/frappe/frappe-bench/logs
    entrypoint: bash -c
    command:
      - >
        wait-for-it -t 120 localhost:3306;
        wait-for-it -t 120 redis-cache:6379;
        wait-for-it -t 120 redis-queue:6379;
        wait-for-it -t 120 redis-socketio:6379;
        export start=`date +%s`;
        until [[-n `grep -hs ^ sites/common_site_config.json | jq -r ".db_host // empty"`]] && \
          [[-n `grep -hs ^ sites/common_site_config.json | jq -r ".redis_cache // empty"`]] && \
          [[-n `grep -hs ^ sites/common_site_config.json | jq -r ".redis_queue // empty"`]];
        do
          echo "Waiting for sites/common_site_config.json to be created";
          sleep 5;
          if (( `date +%s`-start > 120 )); then
            echo "could not find sites/common_site_config.json with required keys";
            exit 1
          fi
        done;
        echo "sites/common_site_config.json found";
        bench new-site frontend --no-mariadb-socket --admin-password=admin --db-root-password=admin --install-app dokos --install-app hrms --set-default || exit 0;
        echo; echo "Site creation completed successfully"; echo;

  frontend:
    <<: *backend_defaults
    command: nginx-entrypoint.sh
    environment:
      BACKEND: backend:8000
      FRAPPE_SITE_NAME_HEADER: frontend
      SOCKETIO: websocket:9000
      UPSTREAM_REAL_IP_ADDRESS: 127.0.0.1
      UPSTREAM_REAL_IP_HEADER: X-Forwarded-For
      UPSTREAM_REAL_IP_RECURSIVE: "off"
      PROXY_READ_TIMOUT: 120
      CLIENT_MAX_BODY_SIZE: 50m
    ports:
      - "8080:8080"

  queue-default:
    <<: *backend_defaults
    command: bench worker --queue default

  queue-long:
    <<: *backend_defaults
    command: bench worker --queue long

  queue-short:
    <<: *backend_defaults
    command: bench worker --queue short

  redis-queue:
    <<: *restart_on_failure
    image: redis:6.2-alpine
    volumes:
      - redis-queue-data:/data

  redis-cache:
    <<: *restart_on_failure
    image: redis:6.2-alpine
    volumes:
      - redis-cache-data:/data

  redis-socketio:
    <<: *restart_on_failure
    image: redis:6.2-alpine
    volumes:
      - redis-socketio-data:/data

  scheduler:
    <<: *backend_defaults
    command: bench schedule

  websocket:
    <<: *backend_defaults
    command: node /home/frappe/frappe-bench/apps/frappe/socketio.js

volumes:
  redis-queue-data:
  redis-cache-data:
  redis-socketio-data:
  sites:
  logs:

```

---

<div class="post-metadata">

**Author:** ![corentin](https://community.dokos.io/user_avatar/community.dokos.io/corentin/32/305_2.png) [@corentin](https://community.dokos.io/u/corentin)\
**Post date:** [Octobre 24, 2023, 10:47 UTC](https://community.dokos.io/t/execution-containeurisee-avec-la-db-locale/800/2 "2023-10-24T10:47:52Z")

</div>

> [@ledruide](#):
>
> ```auto
> environment:
> DB_HOST: localhost
> DB_PORT: "3306"
> 
> ⋮
> 
> wait-for-it -t 120 localhost:3306;
> 
> ```

Bonjour Nicolas,

Ici, `localhost` correspond au conteneur lui-même, et non pas à la machine hôte. Je pense que c’est le problème.

Une partie de la solution est :

> <https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach>

---

<div class="post-metadata">

**Author:** ![ledruide](https://community.dokos.io/user_avatar/community.dokos.io/ledruide/32/883_2.png) [@ledruide](https://community.dokos.io/u/ledruide)\
**Post date:** [Octobre 24, 2023, 10:50 UTC](https://community.dokos.io/t/execution-containeurisee-avec-la-db-locale/800/3 "2023-10-24T10:50:06Z")

</div>

> [@ledruide](#):
>
> ```auto
> redis-queue-data:
> redis-cache-data:
> 
> ```

Merci Corentin, bien vu!  
Je vais creuser dans cette direction 😉
