@sergey228_G

Не работает связь между двумя контейнерами api и front?

api env

APP_HOST=l.mkk.api.loc
APP_URL=http://${APP_HOST}
COMPOSE_PROJECT_NAME=mkksoft
APP_EXT_PORT=80


api docker-compose.yml
version: '3'
services:

  #PHP Service
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
      args:
        TZ: Europe/Moscow
        USER_GROUP_ID: "${USER_GROUP_ID}"
        USER_ID: "${USER_ID}"
    extra_hosts:
        - 'host.docker.mkk:host-gateway'
    restart: unless-stopped
    tty: true
    environment:
      - SERVICE_TAGS=dev
    working_dir: /var/www
    volumes:
      - ./:/var/www
      - ./../../.ssh:/home/www/.ssh
      - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
        - web
        - mkk
    labels:
      - traefik.enable=false
    depends_on:
      - pgsql
#    extra_hosts:
#      - "${APP_HOST}:host-gateway"

  #Nginx Service
  nginx:
    image: nginx:alpine
    restart: unless-stopped
    tty: true
    #    network_mode: host
#    ports:
#        - "8082:8082"
#    network_mode: host
    environment:
      NGINX_ENVSUBST_TEMPLATE_SUFFIX: ".conf"
      FASTCGI_PASS: "${COMPOSE_PROJECT_NAME}_app_1:9000"
    volumes:
      - ./:/var/www
      - ./docker/nginx/templates:/etc/nginx/templates
      - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
    labels:
      - traefik.backend=${COMPOSE_PROJECT_NAME}_webserver_1
      - traefik.frontend.rule=Host:${APP_HOST}
      - traefik.docker.network=web
      - traefik.port=80
    networks:
        - web
        - mkk
    depends_on:
      - app

#  #PostgreSQL Service
  pgsql:
    image: postgres
    restart: unless-stopped
    tty: true
    ports:
      - "${DB_PGSQL_EXT_PORT}:5432"
    environment:
      - TZ="Europe/Moscow"
      - POSTGRES_DB=${DB_DATABASE}
      - POSTGRES_USER=${DB_USERNAME}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      - mkk
    labels:
      - traefik.enable=false

#Docker Networks
networks:
    web:
        external: true
    mkk:
        driver: bridge

#Volumes
volumes:
  pgdata:
    driver: local


front env параметры

API_URL=host.docker.mkk  (до этого с другими конфигами пробовал host.docker.internal - тоже не работало )
API_SPACE=main
API_TOKEN=7|esnSJjYVgCEIKrMuIs7M96XBJCP8ypGVIQIgFZEK


front docker-compose.yml

version: '3'
services:

    #PHP Service
    app:
        build:
            context: .
            dockerfile: docker/php/Dockerfile
            args:
                TZ: Europe/Moscow
                USER_GROUP_ID: "${USER_GROUP_ID}"
                USER_ID: "${USER_ID}"
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        restart: unless-stopped
        tty: true
        environment:
            - SERVICE_TAGS=dev
        working_dir: /var/www
        volumes:
            - ./:/var/www
            - ./../../.ssh:/home/www/.ssh
            - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
        networks:
            - mkk
        labels:
            - traefik.enable=false
        depends_on:
            - pgsql
    #    extra_hosts:
    #      - "${APP_HOST}:host-gateway"

    #Nginx Service
    nginx:
        image: nginx:alpine
#        ports:
#            - ${APP_EXT_PORT:-81}:80
        restart: unless-stopped
        tty: true
        environment:
            NGINX_ENVSUBST_TEMPLATE_SUFFIX: ".conf"
            FASTCGI_PASS: "${COMPOSE_PROJECT_NAME}_app_1:9000"
        volumes:
            - ./:/var/www
            - ./docker/nginx/templates:/etc/nginx/templates
            - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
        labels:
            - traefik.backend=${COMPOSE_PROJECT_NAME}_webserver_1
            - traefik.frontend.rule=Host:${APP_HOST}
            - traefik.docker.network=web
            - traefik.port=80
        networks:
            - mkk
            - web
        depends_on:
            - app

    #  #PostgreSQL Service
    pgsql:
        image: postgres
        restart: unless-stopped
        tty: true
        ports:
            - "${DB_PGSQL_EXT_PORT}:5432"
        environment:
            - TZ="Europe/Moscow"
            - POSTGRES_DB=${DB_DATABASE}
            - POSTGRES_USER=${DB_USERNAME}
            - POSTGRES_PASSWORD=${DB_PASSWORD}
        volumes:
            - pgdata:/var/lib/postgresql/data
        networks:
            - mkk
        labels:
            - traefik.enable=false

#Docker Networks
networks:
    web:
        external: true
    mkk:
        external: true

#Volumes
volumes:
    pgdata:
        driver: local


получаю ошибку вида ) контейнеры находятся в одной сети)
cURL error 6: Could not resolve host: l.mkk.api.loc

или

Connection timed out after 5000 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for host.docker.internal/api/references/credit-products?where%5Bshow_in_lk%5D=1&columns%5B0%5D=id&columns%5B1%5D=name&columns%5B2%5D=min_amount&columns%5B3%5D=max_amount&columns%5B4%5D=min_period&columns%5B5%5D=max_period&columns%5B6%5D=percent


в хостах прописано след

127.0.0.1 l.mkk.api.loc
127.0.0.1 l.mkk.lk.loc
127.0.0.1 host.docker.internal
127.0.0.1 gateway.docker.internal
  • Вопрос задан
  • 111 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы