如何链接和缩放多个Docker容器? [英] How do I link and scale multiple docker containers?

查看:83
本文介绍了如何链接和缩放多个Docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Selenium Grid的Docker映像并行执行测试.

I would like to use Selenium Grid's Docker images to execute tests in parallel.

为此,我希望将每个测试套件分发到不同的浏览器节点.每个节点都必须与自己的dockerized服务器配对,以便测试可以运行.所以我的问题是链接容器对的最佳方法是什么?

In order to do so, I wish to dispatch each test suite to a different browser node. Each node would have to be paired up with its own dockerized server so that the tests may run. So my question is what is the best way to link the container pairs?

是否可以通过Docker Compose轻松扩展服务器节点对?

Is there a way to easily scale the server-node pairs, perhaps with Docker Compose?

我对所有这些都还很陌生,因此,如果我要实现的目标不是很明确,我深表歉意.

I am pretty new to all of this, so apologies if what I am trying to achieve isn't very clear.

推荐答案

我不是100%清楚需要将每个测试套件分派到不同的节点,但是听起来像这样应该可以满足您的要求:

I'm not 100% clear on the need to dispatch each test suite to a different node but it sounds like something like this should meet your requirements:

hub:
  image: selenium/hub:2.53.0
  ports:
    - "4444:4444"
firefox:
  image: selenium/node-chrome:2.53.0
  links:
    - hub
chrome:
  image: selenium/node-chrome:2.53.0
  links:
    - hub

如果将其保存为 docker-compose.yml ,然后 cd 进入目录,则可以执行以下操作:

If you save this in a directory as docker-compose.yml and then cd into the directory you can do something like:

docker-compose up -d
docker-compose scale firefox=3 chrome=3

这将在每个浏览器中为您提供3个节点,并且selenium集线器将处理将测试分配给这些节点,以便它们一次仅运行一组测试.

This will give you 3 nodes with each browser and the selenium hub will handle assigning your tests to the nodes such that they are only running a single set of tests at once.

然后您告诉所有测试使用远程Webdriver&您可以控制每组测试使用哪种浏览器:

You then tell all of your tests to use a remote webdriver & you are able to control which browser gets used for each set of tests:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

driver = webdriver.Remote(
   command_executor='http://127.0.0.1:4444/wd/hub',
   desired_capabilities=DesiredCapabilities.CHROME)
driver.get("http://www.seleniumhq.org/")

显然,您需要对其进行修改以使用所需的语言来编写测试.我刚刚在python中发布了一个快速示例,以使您如愿以偿,因为您没有指定语言&这是我最熟悉的.

Obviously you would need to modify this to use your desired language to write the tests in. I just posted a quick example in python to get you going as you didn't specify a language & that is what I am most familiar with.

满足您实际需求的可能方法:

Possible way of meeting your actual requirement:

hub:
  image: selenium/hub:2.53.0
  links: 
    - app
firefox:
  image: selenium/node-chrome:2.53.0
  links:
    - hub
chrome:
  image: selenium/node-chrome:2.53.0
  links:
    - hub
test:
  image: your/testimage
  links:
    - hub
app:
  image: your/appimage

然后您可以通过运行(在docker-compose.yml所在的目录中)启动整个安装程序的多个实例:

You could then start multiple instances of the whole setup by running (in the directory where the docker-compose.yml is):

docker-compose --project-name <identifier> up -d

如果将< identifier> 更改为每个实例唯一的名称,则可以一次运行多个实例.您可能还想在测试容器中添加 volume ,以便可以保留结果/日志/屏幕截图,但是我对设置的了解不多,无法告诉您如何执行操作.

If you change <identifier> to something unique for each instance then you can have multiple instances running at one time. You would also probably want to add a volume to your test container so that you can persist results/logs/screenshots but I don't really know enough about the setup to tell you how to do that.

在这种情况下,我会问您是否需要硒集线器,但这确实增加了一些方便,因此您可能仍希望使用它.

I would question whether you need the selenium-hub in this case but it does add some convenience so you may still wish to use it.

这篇关于如何链接和缩放多个Docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆