简体   繁体   English

在docker容器中获取弹性beanstalk环境变量

[英]Get elastic beanstalk environment variables in docker container

So, i'm trying not to put sensitive information on the dockerfile. 所以,我试图不在dockerfile上放置敏感信息。 A logical approach is to put the creds in the ebs configuration (the GUI) as a ENV variable. 逻辑方法是将ebs配置(GUI)中的信用作为ENV变量。 However, docker build doesn't seem to be able to access the ENV variable. 但是,docker build似乎无法访问ENV变量。 Any thoughts? 有什么想法吗?

在此输入图像描述

FROM jupyter/scipy-notebook

USER root

ARG AWS_ACCESS_KEY_ID
RUN echo {$AWS_ACCESS_KEY_ID}

Putting sensitive information (for a Dockerfile to use) can be either for allowing a specific step of the image to run (build time), or for the resulting image to have that secret still there at runtime. 放置敏感信息(供Dockerfile使用)可以是允许运行图像的特定步骤(构建时间),也可以是生成的图像在运行时仍保留该秘密。
For runtime, if you can use the latest docker 1.13 in a swarm mode configuration, you can manage secrets that way 对于运行时,如果您可以在群集模式配置中使用最新的docker 1.13,则可以通过这种方式管理机密

But the first case (build time) is typically for passing credentials to an http_proxy , and that can be done with --build-arg : 但第一种情况(构建时间)通常用于将凭据传递给http_proxy ,这可以通过--build-arg

 docker build --build-arg HTTP_PROXY=http://...

This flag allows you to pass the build-time variables that are accessed like regular environment variables in the RUN instruction of the Dockerfile. 此标志允许您传递在Dockerfile的RUN指令中像常规环境变量一样访问的构建时变量。
Also, these values don't persist in the intermediate or final images like ENV values do. 而且,这些值不会像ENV值那样在中间或最终图像中持续存在。

In that case, you would not use ENV , but ARG : 在这种情况下,你不会使用ENVARG

ARG <name>[=<default value>]

The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg <varname>=<value> flag ARG指令使用--build-arg <varname>=<value>标志定义一个变量,用户可以使用docker build命令在构建时将该变量传递给构建器。

I assume that for every deployment you create a new Dockerrun.aws.json file with the correct docker image tag for that deployment. 我假设您为每个部署创建一个新的Dockerrun.aws.json文件,其中包含该部署的正确docker image标记。 At deployment stage, you can inject environment values which will then be used in docker run command by EB agent. 在部署阶段,您可以注入环境值,然后由EB代理在docker run命令中使用这些值。 So your docker containers can now access to these environment variables. 因此,您的docker容器现在可以访问这些环境变量。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM