我有以下设置:
selenium-chrome:
image: selenium/node-chrome-debug:3.141.59-neon
container_name: chrome-e2e
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
- SHM-SIZE=2g
- GRID_DEBUG=false
- NODE_MAX_SESSION=1
- NODE_MAX_INSTANCES=5
- TZ=Europe/Brussels
hostname: chrome-e2e
networks:
- build-network
ports:
- 5900:5900
volumes:
- ./target:/home/seluser/Downloads
Selenium 测试在容器内部运行,实际测试代码在容器外部。我们使用 Maven 处理容器的生命周期。
正如你所看到的,我将 Chrome 下载文件夹(在容器内)安装到了target
-我的应用程序的文件夹。一切都安装良好,但当 Chrome 尝试下载文件时,写入权限被拒绝/home/seluser/Downloads
。
UID 和 GID/home/seluser/Downloads
Docker 设置为 2100:2100。 Chrome 本身是通过seluser
user.
我需要做什么才能给予seluser
写入2100拥有的文件夹的权限?
提前致谢。
问候
Linux 中的绑定挂载不会对 uid 或 gid 执行任何命名空间,并且主机挂载在幕后运行绑定挂载。因此,如果容器内的 uid 与主机上的 uid 不同,您将遇到权限问题。我已经在其他容器中使用修复权限脚本解决了这个问题。实现类似于以下 Dockerfile:
FROM selenium/node-chrome-debug:3.141.59-neon
COPY --from=sudobmitch/base:scratch /usr/bin/gosu /usr/bin/fix-perms /usr/bin/
COPY entrypoint.sh /entrypoint.sh
# use a chmod here if you cannot fix permissions outside of docker
RUN chmod 755 /entrypoint.sh
USER root
ENTRYPOINT [ "/entrypoint.sh" ]
入口点.sh 看起来像:
#!/bin/sh
if [ "$(id -u)" = "0" -a -d "/home/seluser/Downloads" ]; then
fix-perms -r -u seluser /home/seluser/Downloads
exec gosu seluser /opt/bin/entry_point.sh "$@"
else
exec /opt/bin/entry_point.sh "$@"
fi
这里发生的事情是容器以 root 身份启动,并且 fix-perms 脚本调整seluser
容器内的 uid 相匹配/home/seluser/Downloads
目录。这exec gosu
然后以新 pid 1 的 seluser 身份运行容器进程。
您可以在以下位置查看用于实现此功能的代码:https://github.com/sudo-bmitch/docker-base https://github.com/sudo-bmitch/docker-base
我在几次演讲中讨论过这种方法,包括:https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#fix-perms https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#fix-perms
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)