如何将我的外部docker网络与Guzzle或JQuery结合使用

时间:2019-04-14 17:38:58

标签: docker-compose

我创建了两个docker容器,一个API和一个前端。我能够创建一个名为“ webserver”的外部网络

我还能够使每个容器成功ping另一个容器。 问题是如何使用Guzzle或JQuery例如与我的API通信?

做这样的事情是行不通的,因为我的网络被解释为字符串:

$this->myClient = new Client([
    'base_uri' => 'webserver'
    'timeout' => $this->timeout,
]);

这是我的docker撰写文件:

version: "3"

services:
  webserver:
    build:
      context: ./build/vhost
    container_name: 'ss-api-webserver'
    restart: 'always'
    hostname: 'ssdev'
    ports:
      - "80:80"
      - "443:443"
    networks:
      - backend
      - frontend
    depends_on:
      - mariadb 
    volumes:
      - ${DOCUMENT_ROOT-./www/api}:/var/www/dev.api.simplysweeps.com
      - ${PHP_INI-./config/php}:/usr/local/etc/php
      - ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
      - ${LOG_DIR-./logs/apache2}:/var/log/apache

 frontend:
   build:
     context: ./build/frontend
   container_name: 'ss-fe-webserver'
   restart: 'always'
   hostname: 'ssdevfe'
   ports:
     - "82:80"
   networks:
     - frontend

   volumes:
     - ${DOCUMENT_ROOT_FE-./www/simplysweeps}:/var/www/dev.simplysweeps.com
     - ${PHP_INI-./config/php}:/usr/local/etc/php
     - ${VHOSTS_DIR_FE-./config/frontend}:/etc/apache2/sites-enabled
     - ${APACHE_LOG_DIR-./logs/apache2}:/var/log/apache
  mariadb:
    build: ./build/mariadb
    container_name: 'ss-api-maria-db'
    restart: 'always'
    ports:
      - "3306:3306"
    networks:
      - backend
    volumes: 
      - db-data:/var/lib/mysql
      - ${MYSQL_LOG_DIR-./logs/mariadb}:/var/log/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=buntsh4k4l4k4
      - MYSQL_DATABASE= mysql
      - MYSQL_USER= root
      - MYSQL_PASSWORD= buntsh4k4l4k4

networks:
  backend:
  frontend:
    external: true


volumes:
 db-data:

0 个答案:

没有答案