简体   繁体   English

使用 env_file 参数指定的 Docker 组合环境变量在 dockerfile 中不起作用

[英]Docker compose environment variables specified with env_file parameter not working inside the dockerfile

This is a snippet of my docker-compose.yml file which I'm running with docker-compose build percona_dev .这是我docker-compose.yml docker-compose build percona_dev运行docker-compose.yml文件的片段。

percona_dev:
  build: docker/percona
  dockerfile: percona-dev
  env_file: docker.env

I've specified environment variables in docker.env like this:我在docker.env指定了环境变量,如下所示:

USERNAME=xxx
PASSWORD=xxx
DESKTOP_IP=192.168.1.1
PLAYBOOK_LOCATION=/path/to/location/

This is the relevant portion of my Dockerfile called percona-dev :这是我的Dockerfile名为percona-dev的相关部分:

FROM percona:5.6.24
MAINTAINER xxx

RUN apt-get update && apt-get install wget

RUN wget --ftp-user=$USERNAME --ftp-password=$PASSWORD ftp://$DESKTOP_IP/$PLAYBOOK_LOCATION/inventory/localhost -O /tmp/playbook/hosts

EXPOSE 3306
ENTRYPOINT [“/usr/bin/mysql”]

Unfortunately the environment variables don't get recognized and the build fails with:不幸的是,环境变量没有被识别,构建失败:

Step 5 : RUN wget --ftp-user=$USERNAME --ftp-password=$PASSWORD ftp://$DESKTOP_IP/$PLAYBOOK_LOCATION/inventory/localhost -O /tmp/playbook/hosts
 ---> Running in 3595b5ce9581
ftp:////inventory/localhost: Invalid host name.
Service 'percona_dev' failed to build:

How do I make sure I can run the build without exposing sensitive environment variables in my Dockerfile or in thefilesystem layer history of my image?我如何确保我可以运行构建而不在我的 Dockerfile 或我的图像的文件系统层历史记录中暴露敏感的环境变量?

environment variables are not available to the build step.环境变量不可用于构建步骤。 See this proposal for making that more obvious in compose and this feature request to support the new build args added to docker 1.9.请参阅此提案,以在 compose 和此功能请求中使一点更加明显,以支持添加到 docker 1.9 的新构建参数。

The build args will do what you need.构建参数将满足您的需求。

暂无
暂无

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

相关问题 docker 撰写 env_file 在我的撰写文件中不起作用 - docker compose env_file not working inside my compose file 用外部的实际环境覆盖 docker-compose env_file 中的变量 - Override variables in docker-compose env_file with the actual environment from the outside 多个docker compose文件,指定了env_file - Multiple docker compose files, with env_file specified Docker compose is using the env which was built by Dockerfile, instead of using env_file located in docker-compose.yml directory because of webpack - Docker compose is using the env which was built by Dockerfile, instead of using env_file located in docker-compose.yml directory because of webpack Docker compose:如何定义指向容器内而非物理服务器内某些文件的env_file - Docker compose : how to define env_file pointing to some file inside the container and not the physical server 如何通过在 docker-compose.yaml 中传递 env_file 从 dockerfile 容器重建 create-react-app - How to rebuild create-react-app from a dockerfile container by passing env_file in docker-compose.yaml 使用env_file在撰写文件中设置变量时发出警告 - Warning when setting variables in compose file with env_file 如何从env_file获取docker-compose的端口? - How to get port of docker-compose from env_file? 使用服务env_file的Docker-compose错误 - Docker-compose error with service env_file Ansible 使用 env_file 验证 docker-compose 并发送到主机 - Ansible validate docker-compose with env_file and send to host
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM