在主机系统上使用Docker撰写运行容器的文件

我想用我的容器使用Excel文件和一些文件夹。 我正在使用卷,但不知道我的作文是什么问题。

seleniumhub: image: selenium/hub ports: - "4444:4444" firefoxnode: image: selenium/node-firefox-debug ports: - "5901:5900" links: - "seleniumhub:hub" shm_size: '2gb' environment: - "NODE_MAX_SESSION=2" - "NODE_MAX_INSTANCES=2" chromenode2: image: selenium/node-chrome-debug ports: - "5902:5900" links: - "seleniumhub:hub" shm_size: '2gb' environment: - "NODE_MAX_SESSION=2" - "NODE_MAX_INSTANCES=2" test: image: raveena1/dilsel ports: - 4579 links: - "seleniumhub:hub" container_name: mywebcontainer **volumes: - /$$(pwd)/Newfolder/Config/framework-config.properties:/var/lib/docker/** 

我想在我的容器中使用上面的属性文件,我怎么能实现这个?

我不认为docker-compose可以解释撰写文件中的bash命令。 但是,你可以做的是使用环境variables。 在你的情况下,你可能想要使用$PWD

 [...] volumes: - $PWD/Newfolder/Config/framework-config.properties:/var/lib/docker/ [...] 

这将解释环境variables$PWD (它parsing为您当前正在运行的directy)并将其挂载到/var/lib/docker

以下是在docker-compose中使用环境variables的一个例子:

泊坞窗,compose.yml:

 test: image: debian:stretch-slim ports: - 4579 container_name: mywebcontainer volumes: - $PWD/:/current_directory_of_host entrypoint: "ls -l /current_directory_of_host" 

docker-compose up启动这个容器docker-compose up 。 您应该看到当前工作目录中的文件列表。

您也可以使用自定义环境variables: CUSTOM_ENV=$(pwd) docker-compose up 。 这将转发CUSTOM_ENVCUSTOM_ENV -compose,这可以在你的docker-compose.yml中使用。