Bor*_*rte 8 selenium docker docker-compose
情况:
我有一个selenium app(在python中)将自己连接到网站上的帐户,以便下载几个CSV文件.要运行它,我使用docker(和docker-compose)这是我的docker-compose.yml文件
version: '3'
services:
selenium:
build:
context: .
dockerfile: compose/selenium/Dockerfile
ports:
- "4444:4444"
volumes:
- /dev/shm:/dev/shm
- download-folder:/home/seluser/downloads
enma:
build:
context: .
dockerfile: compose/enma_daio/Dockerfile
depends_on:
- selenium
volumes:
- download-folder:/data/selenium-downloads
env_file:
- .env
restart: always
volumes:
download-folder:
Run Code Online (Sandbox Code Playgroud)
我selenium's Dockerfile只是一种downloads使用官方selenium docker图像创建文件夹的方法
FROM selenium/standalone-chrome
RUN mkdir -p /home/seluser/downloads
Run Code Online (Sandbox Code Playgroud)
要运行我的任务,我使用:
docker-compose run -d enma daio arg0 arg1 arg2
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我也使用了entrypoint.sh:
#!/bin/bash
set -e
cd /app
# Selenium takes a bit of time before being up so we wait until we can reach it
function selenium_ready(){
curl selenium:4444 &>/dev/null
}
until selenium_ready; do
>&2 echo "Waiting for selenium..."
sleep 1
done
if [ "$1" = 'daio' ]; then
shift
exec python enma.py $@
fi
exec "$@"
Run Code Online (Sandbox Code Playgroud)
问题:
当我同时运行多个实例(在同一网站上的不同帐户上)时,他们共享same selenium container,所以same volume.所有下载的文件混合在一起,我不知道哪个文件来自哪个run.
我想做什么:
我selenium container每次运行新任务时都想创建另一个.或者找到使用不同卷的其他方法.
这听起来像你应该在执行时将--project-nameorp标志传递给 docker-composedocker-compose run。
默认情况下,docker-compose 根据您的项目名称创建卷和容器名称,并默认使用当前目录的名称。因此,在您的情况下,您将有一个卷名称<cwd>_download-folder。带有容器名称<cwd>_selenium和<cwd>_enma.
如果您想selenium在每个卷上创建新卷和新容器docker-compose run则只需覆盖其项目名称即可。
所以如果你这样做
$ docker-compose -p name1 run -d enma daio arg0 arg1 arg2
$ docker-compose -p name2 run -d enma daio arg0 arg1 arg2
您最终将得到两个创建的卷和四个容器。这似乎适合您的需求,这将消除enma容器共享相同的卷。
仅供参考,您可以通过运行查看已创建的卷docker volume ls。
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
97 次 |
| 最近记录: |