2

我一直在使用 Docker for Mac(版本 1.12.0-a(内部版本:11213))。

我正在尝试使用图像来运行我的量角器测试。我正在使用以下命令运行测试: docker run -it --privileged --rm --net=host -v /dev/shm:/dev/shm -v $(pwd):/protractor webnicer/protractor-headless src/test/e2e/config/docker-config.js

这是我的配置文件:

exports.config = {

  onPrepare: function() {
    global.nodeModulesPath = '../../main/webapp/node_modules/';
    global.mongoConnection = '127.0.0.1:27017';
    global.dbName = 'DB_name'; 

    var width = 1280;
    var height = 768;
    browser.driver.manage().window().setSize(width, height);
  },

  framework: 'jasmine2',

  baseUrl: 'http://127.0.0.1:8080/my-app/',

  specs: ['../tests/**/*.spec.js'],

  restartBrowserBetweenTests: false,

  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    isVerbose: true,
    includeStackTrace: true
  }
};

Mongo 在容器内运行,webnicer/protractor-headless容器可以看到 Mongo 并可以插入所有数据(我检查了 Mongo 并通过 确认docker logs)。

但看起来webnicer/protractor-headless看不到localhost:8080应用程序的部署位置。

看起来这与--net=host选项有关,但我不确定。有人有想法或建议吗?

4

1 回答 1

0

从图片页面:

为什么 --net=host?

仅当 dockerised Protractor 针对主机上的 localhost 运行时,才需要此选项。想象一下这个场景:你在本地机器上运行一个 http 测试服务器,比如说在端口 8000 上。你在浏览器中输入http://localhost:8000,一切顺利。然后你想对同一个 localhost:8000 运行 dockerised Protractor。如果您不使用 --net=host 容器将接收桥接接口和它自己的环回,因此容器内的 localhost 将引用容器本身。使用 --net=host 您允许容器共享主机的网络堆栈,并在 Protractor 针对 localhost 运行时正确引用主机。

于 2016-09-02T15:46:55.527 回答