如何在同一堆栈网络中连接两个服务?

问题描述 投票:0回答:1

我有docker-compose.yaml文件,如:

version: '3.7'
services:
  passbolt:
    image: passbolt/passbolt
    hostname: passbolt
    container_name: passbolt
    ports:
      - 80:80
      - 443:443
    environment:
      DATASOURCES_DEFAULT_HOST: mariadb
      DATASOURCES_DEFAULT_USERNAME: passbolt
      DATASOURCES_DEFAULT_PASSWORD: passbolt
      DATASOURCES_DEFAULT_DATABASE: passbolt
      APP_FULL_BASE_URL: https://my.url/
    networks:
      - passbolt_network
    depends_on:
      - mariadb
  mariadb:
    image: mariadb
    hostname: mariadb
    container_name: mariadb
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: passbolt
      MYSQL_USER: passbolt
      MYSQL_PASSWORD: passbolt
    networks:
      - passbolt_network
networks:
  passbolt_network:
    driver: overlay

我是docker stack deploy -c docker-compose.yaml test的runnig堆栈并且passbolt服务由于异常:连接数据库时出现问题而退出:SQLSTATE [HY000] [2002](...)

中的连接被拒绝
docker docker-swarm docker-networking docker-stack
1个回答
0
投票
您也可以使用网络别名:

version: '3.7' services: passbolt: image: passbolt/passbolt hostname: passbolt container_name: passbolt ports: - 80:80 - 443:443 environment: DATASOURCES_DEFAULT_HOST: alias_to_mariadb DATASOURCES_DEFAULT_USERNAME: passbolt DATASOURCES_DEFAULT_PASSWORD: passbolt DATASOURCES_DEFAULT_DATABASE: passbolt APP_FULL_BASE_URL: https://my.url/ networks: - passbolt_network depends_on: - mariadb mariadb: image: mariadb hostname: mariadb container_name: mariadb ports: - 3306:3306 environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: passbolt MYSQL_USER: passbolt MYSQL_PASSWORD: passbolt networks: passbolt_network: aliases: - "alias_to_mariadb" networks: passbolt_network: driver: overlay

© www.soinside.com 2019 - 2024. All rights reserved.