使用docker compose在主机系统上使用运行容器的文件

问题描述 投票:0回答:1

我想在我的容器中使用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 docker-compose docker-volume
1个回答
0
投票

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

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

这将解释环境变量$PWD(它解析为您当前的工作直接)并将其挂载到/var/lib/docker

下面是在docker-compose中使用环境变量的示例:

码头工人,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启动这个容器。您应该看到当前工作目录中的文件列表。

您还可以使用自定义环境变量:CUSTOM_ENV=$(pwd) docker-compose up。这将把CUSTOM_ENV转发到docker-compose,它可以在你的docker-compose.yml中使用。

© www.soinside.com 2019 - 2024. All rights reserved.