【问题标题】:Laravel dusk with docker-composeLaravel 黄昏与 docker-compose
【发布时间】:2019-10-15 20:33:44
【问题描述】:

我在我的 Laravel 应用程序中使用 doke-compose,我的 docker-compose.yml 文件看起来像这样

version: '3'
services:
  nginx:
    build:
      context: ./
      dockerfile: docker/nginx.docker
    volumes:
      - ./apps/laravel/:/var/www
      - ./docker/nginx/ssl:/etc/nginx/ssl
    ports:
      - "8087:443"
    links:
      - php-fpm
    container_name: insystems-nginx
 php-fpm:
   build:
     context: ./
     dockerfile: docker/php-fpm.docker
     args:
       - UID=${UID}
   volumes:
     - ./apps/laravel/:/var/www
     - ./docker/php/custom.ini:/usr/local/etc/php/conf.d/custom.ini
   links:
     - mysql
   environment:
     - "DB_PORT=3306"
     - "DB_HOST=mysql"
     - "PHP_IDE_CONFIG=serverName=localhost"
   user: www-data
   container_name: insystems-php-fpm
php-cli:
  build:
    context: ./
    dockerfile: docker/php-cli.docker
    args:
      - UID=${UID}
  volumes:
    - ./apps/laravel/:/var/www
  links:
    - mysql
    - selenium
  environment:
    - "DB_PORT=3306"
    - "DB_HOST=mysql"
  tty: true
  user: www-data
  container_name: insystems-php-cli
mysql:
  image: mysql:5.7
  volumes:
    - ./storage/docker/mysql:/var/lib/mysql
  environment:
    - "MYSQL_ROOT_PASSWORD=secret"
    - "MYSQL_USER=app"
    - "MYSQL_PASSWORD=secret"
    - "MYSQL_DATABASE=app"
  ports:
    - "33061:3306"
  container_name: insystems-mysql
selenium:
  image: selenium/standalone-chrome:3.0.1-fermium

而 DuskTestCase.php 看起来像这样

<?php

 namespace Tests;

 use Laravel\Dusk\TestCase as BaseTestCase;
 use Facebook\WebDriver\Chrome\ChromeOptions;
 use Facebook\WebDriver\Remote\RemoteWebDriver;
 use Facebook\WebDriver\Remote\DesiredCapabilities;

abstract class DuskTestCase extends BaseTestCase
{
 use CreatesApplication;

 public function setUp(): void
 {
    parent::setUp();
 }

/**
 * Prepare for Dusk test execution.
 *
 * @beforeClass
 * @return void
 */
public static function prepare()
{
    static::startChromeDriver();
}

/**
 * Create the RemoteWebDriver instance.
 *
 * @return \Facebook\WebDriver\Remote\RemoteWebDriver
 */
protected function driver()
{
    $options = (new ChromeOptions)->addArguments([
        '--disable-gpu',
        '--no-sandbox',
        '--window-size=1920,1080',
    ]);

    return RemoteWebDriver::create(
        'http://selenium:4444/wd/hub', DesiredCapabilities::chrome()->setCapability(
            ChromeOptions::CAPABILITY, $options
        )
          //->setCapability('acceptInsecureCerts', true) //@TODO for https test
    );
 }

 protected function baseUrl()
 {
    //@TODO 'http://$_SERVER["REMOTE_ADDR"]:8087'
    return 'http://localhost:8087'
 }
}

当我尝试从 baseUrl() 返回 http://localhost:8087 时,我的测试用例出现错误。 但是如果 return http://172.19.0.1:8087 (172.19.0.1 is $_SERVER["REMOTE_ADDR"]) 工作正常。

问题是我想使用 localhost 而不是 $_SERVER["REMOTE_ADDR"] 并且知道原因。您能否给我一些建议,以将我的测试用例作为 localhost 运行需要进行哪些更改。

【问题讨论】:

    标签: php laravel-5 docker-compose


    【解决方案1】:

    试试:

      selenium:
        image: selenium/standalone-chrome:3.0.1-fermium
        container_name: selenium
    

    或者

      php-fpm: 
       ....
        networks: 
          - app_network 
      selenium:
        image: selenium/standalone-chrome:3.0.1-fermium
        container_name: selenium
        networks:
          - app_network
    

    【讨论】:

      猜你喜欢
      • 2018-02-23
      • 2023-04-01
      • 1970-01-01
      • 2018-01-21
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多