简体   繁体   English

通过 docker-compose 和环境变量将单个文件复制到容器中

[英]Copy single file into container via docker-compose and environmental variable

Any ideas why this isn't putting the file into the container?有什么想法为什么不将文件放入容器中?

k6:
    image: loadimpact/k6:0.32.0
    environment:
        - ENVIRONMENT=${ENVIRONMENT}
        - AMOUNT_OF_USERS=${AMOUNT_OF_USERS}
        - RUN_TIME=${RUN_TIME}
    command: run /test.mjs
    volumes:
        - ./load-test.mjs:/test.mjs # <-- this works
        - ./${USERS_FILE}:/users.csv # <-- this does not work

I'm running with the command:我正在使用以下命令运行:

ENVIRONMENT=bla AMOUNT_OF_USERS=5 RUN_TIME=1m USERS_FILE=users2.csv docker-compose up

I did a check inside the container:我在容器内做了检查:

console.log(exists('users.csv'))
console.log(exists('test.mjs'))

Results:结果:

k6_1      | time="2021-05-24T11:31:51Z" level=info msg=false source=console
k6_1      | time="2021-05-24T11:31:51Z" level=info msg=true source=console

The USERS_FILE variable file exists in the same directory as the current working directory, ie users2.csv . USERS_FILE变量文件与当前工作目录在同一目录下,即users2.csv

If I set the volume to the following it works:如果我将音量设置为以下它可以工作:

- ./users2.csv:/users.csv
volumes:
    - ./load-test.mjs:/test.mjs
    - ${PWD}/${USERS_FILE}:/users.csv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用docker-compose up时访问docker-compose.yml文件内的环境变量 - Accessing environmental variable inside of docker-compose.yml file when using docker-compose up Docker-compose:查看容器中设置的环境变量 - Docker-compose: See what environmental variables are set within a container 使用 Dockerfile 或 Docker-compose 将文件从容器复制到主机 - Copy file from container to host using Dockerfile or Docker-compose 为什么无法通过 docker-compose 将文件挂载在容器上? - Why is File Mounted on Container via docker-compose not Accessible? Docker-compose 启动单个容器 - Docker-compose starts a single container 如何使用 docker-compose 重启单个容器 - How to restart a single container with docker-compose 通过docker-compose文件修改环境json数组变量 - Modify environment json array variable via docker-compose file 使用 docker-compose 文件调度 docker 容器 - Scheduling a docker Container with a docker-compose file Docker:使用 docker-compose 复制文件和目录 - Docker: copy file and directory with docker-compose docker-compose exec导致[Errno 2]没有此类文件或目录:docker容器中的&#39;docker-compose&#39;:&#39;docker-compose&#39; - docker-compose exec causes [Errno 2] No such file or directory: 'docker-compose': 'docker-compose' in docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM