我正在运行一个 Docker Compose 环境,在其中执行一系列 Selenium 测试。为了做到这一点,我正在使用Selenium 提供的图像 https://github.com/SeleniumHQ/docker-selenium。我运行两个容器:一个作为硒集线器另一个作为硒火狐节点。我定义了第三个容器,负责测试执行(我们称之为测试节点).
我创建了一个 Docker 卷,供硒火狐节点和测试节点因此某些文件可以由他们共享。我调了音量selenium_volume
并且它安装在/selenium_tests
.
我很快就遇到了一个问题,因为在两个系统中都为用户创建了该文件夹root
,但用户硒火狐节点默认使用的是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
我尝试运行 chown 命令command
之后entrypoint
但我认为它永远不会达到,因为在entrypoint
继续在前台运行。
我想直接在 docker-compose.yml 上完成所有操作并避免创建任何 Dockerfile,但我不知道目前这是否可行。