我正在运行一个Docker Compose环境,在其中可以执行一系列Selenium测试。为此,我使用了images Selenium provides。我运行两个容器:一个为 Selenium HUB ,另一个为 Selenium Firefox Node 。我定义了第三个容器,该容器负责执行测试(我们将其称为 Tests Node )。
我创建了一个由 Selenium Firefox Node 和 Tests Node 使用的Docker卷,以便它们可以共享某些文件。我称该卷为selenium_volume
,它同时安装在/selenium_tests
上。
我很快就遇到了一个问题,该文件夹在两个系统中都为用户root
创建,但是 Selenium Firefox Node 使用的用户默认为seluser
。它具有读取但没有写入权限,这是我所需要的。
我尝试将以下内容用作容器entrypoint
,因此我将seluser
设为目录的所有者:bash -c 'sudo chown -R seluser:seluser /selenium_tests && /opt/bin/entry_point.sh'
,但它不起作用。
启动容器后,我连接到容器(docker exec -ti selenium-firefox bash
)时,看到该文件夹仍属于root
。如果我随后建立连接,请运行命令sudo chown -R seluser:seluser /selenium_tests && /opt/bin/entry_point.sh'
,文件夹权限将更改,并且我们达到了预期的水平。
我想知道为什么当我手动运行命令时它可以工作,但是在容器的入口点脚本之前通过entrypoint
运行时却不能运行。
目前,我的docker-compose.yml
与以下内容类似:
version: '3.8'
services:
tests-node:
build: .
depends_on:
- selenium-hub
- selenium-firefox
# the wait-for-it.sh command makes the container wait until the Selenium containers are ready to work
entrypoint: ["./wait-for-it.sh", "-t", "15", "selenium-firefox:5555", "--"]
command: ["execute_tests.sh"]
volumes:
- ./remote_reports/:/selenium_tests/reports/
- type: volume
source: selenium_volume
target: /selenium_tests
networks:
selenium_net: {}
selenium-hub:
image: selenium/hub:3.141.59
ports:
- "4444:4444"
networks:
selenium_net: {}
selenium-firefox:
image: selenium/node-firefox:3.141.59
depends_on:
- selenium-hub
entrypoint: bash -c 'sudo chown -R seluser:seluser /selenium_tests && /opt/bin/entry_point.sh'
volumes:
- /dev/shm:/dev/shm
- type: volume
source: selenium_volume
target: /selenium_tests
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
networks:
selenium_net: {}
expose:
- 5555
volumes:
selenium_volume:
networks:
selenium_net:
driver: bridge
我尝试在command
之后以entrypoint
的身份运行chown命令,但我认为它从来没有实现过,因为在entrypoint
期间启动的脚本一直在前台运行。
我想直接在docker-compose.yml上做所有事情,并避免创建任何Dockerfile,但是我不知道这是否可能。
答案 0 :(得分:0)
我找到了可能的解决方案。以此为切入点:
Function DatabaseTable() As ListObject
Static rv As ListObject '<< cache the table here
'if your code gets reset then this will just re-cache the table
If rv Is Nothing then Set rv = wsDatabase.ListObjects("tDatabase")
Set DatabaseTable = rv
End Function
它在后台运行bash -c '( while ! timeout 1 bash -c "echo > /dev/tcp/localhost/5555"; do sleep 1; done ; sudo chown -R seluser:seluser /selenium_tests ) & /opt/bin/entry_point.sh'
之前的部分代码,从而使&
可以正常运行。当端口5555准备就绪时,它最终会将所需文件夹的权限授予entry_point.sh
。
答案 1 :(得分:0)
最简单的方法是在开始测试之前将chmod -R 777 /selenium_tests
添加到execute_tests.sh
。在这种情况下,@ aorestr,您无需更改entrypoint
容器的selenium-firefox
。