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

标签 docker environment-variables docker-compose fig

这是我使用 docker-compose build percona_dev 运行的 docker-compose.yml 文件的片段。

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

我已经在 docker.env 中指定了环境变量,如下所示:

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

这是我的 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”]

不幸的是,环境变量无法被识别,并且构建失败:

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:

如何确保可以运行构建而不暴露 Dockerfile 或镜像的文件系统层历史记录中的敏感环境变量?

最佳答案

环境变量不可用于构建步骤。请参阅this proposal为了使这一点在撰写中更加明显,并且 this feature request支持 docker 1.9 中添加的新构建参数。

构建参数将满足您的需要。

关于Docker 编写使用 env_file 参数指定的环境变量在 dockerfile 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33350985/

相关文章:

docker - 如何安装libsnappy.so.1?

c# - 对在Docker容器上运行的C#dot net应用程序进行性能分析

installation - InnoSetup,展开环境变量(使用 {reg :. ..} 从注册表值获取)

bash - 为什么 bash 从字面上使用单引号和双引号?

docker-compose - Docker Compose 端口问题。无法在 localhost 上启动 docker 项目

docker - 在Windows 7上升级docker-compose版本

nginx - docker上的nginx不适用于位置URL

mysql - 未知的 MySQL 服务器主机 'db' Rails 和 Docker

java - 如何从Java(而不是System.properties)读取 "OS variables"

c# - Docker for C# 核心(linux 类型)行为 - 与镜像构建相关