情况:
我有一个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:
我的selenium's Dockerfile
只是使用官方selenium docker image创建downloads
文件夹的一种方法
FROM selenium/standalone-chrome
RUN mkdir -p /home/seluser/downloads
要运行任务,请使用:
docker-compose run -d enma daio arg0 arg1 arg2
顺便说一句,我还使用了一个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 "$@"
问题:
当我同时(在同一网站上的不同帐户上)运行多个实例时,它们共享same selenium container
,因此也共享same volume
。所有下载的文件都混合在一起,我不知道哪个run
来。
我想做什么:
每次运行新任务时,我都想创建另一个selenium container
。或者找到其他方法来使用不同的卷。
答案 0 :(得分:3)
听起来,您在执行--project-name
时应该将p
或docker-compose run
标志传递给docker-compose。
默认情况下,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
查看已创建的卷。
希望这会有所帮助。