configurationDockerfile以设置AWSconfiguration

我刚开始看Docker 。 我有一个节点应用程序,resize和图像,然后发送一个SQS消息完成后。 我设法创build了我的应用程序的泊坞窗图像,从我的本地机器复制它,但遇到了问题,我不能设置包含我的client_idclient_secret发送SQS消息的AWS varibales。

有没有人遇到过这个问题?

我需要在我的dockerfile写入哪些命令来设置awsvariables?

这是我的dockerfile

 FROM ubuntu:latest #install node and npm RUN apt-get update && \ apt-get -y install curl && \ curl -sL https://deb.nodesource.com/setup | sudo bash - && \ apt-get -y install python build-essential nodejs #install imagemagick, graphicsmagick and set-up aws-cli to send SQS messages RUN sudo apt-get -y install imagemagick RUN sudo apt-get -y install graphicsmagick RUN sudo apt-get install unzip RUN curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" RUN unzip awscli-bundle.zip RUN sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws #set-up environment variables for AWS #at some point set-up git and fetch repository from git # Provides cached layer for node_modules ADD package.json /tmp/package.json RUN cd /tmp && npm install RUN mkdir -p /home/image-resizer && cp -a /tmp/node_modules /home/image-resizer/ #bundle source code into image COPY . /home/image-resizer 

我认为有关环境variables的答案是很好的解决scheme。 要提供替代scheme,或者如果您使用文件进行aws身份validation,则可以使用docker卷来安装这些文件。

将主机目录挂载为数据卷

除了使用-v标志创build一个卷之外,你还可以从你的Docker守护进程的主机挂载一个目录到一个容器中。

注意:如果您使用的是Boot2Docker,那么您的Docker守护进程只能访问您的OSX / Windows文件系统。 Boot2Docker会尝试自动共享您的/ Users(OSX)或C:\ Users(Windows)目录,因此您可以使用docker run -v / Users /:/ …(OSX)或docker run来挂载文件或目录。 v / c / Users /:/

取自https://docs.docker.com/userguide/dockervolumes/

这个解决scheme的缺点是假定config文件夹在一个固定的位置。

您可以使用ENV在Docker中设置您的环境variables。 例如。

 ENV PORT=9000 ENV LANG=en_US.utf8 

但是,秘密信息不应该embedded到Dockerfile中,您可以使用-eparameter passing或使用文本文件,并通过–env-fileparameter passing给docker 。 当你登顶到SVN或git时,你应该忽略文本文件。

你为什么不把所需的variables作为环境variables传递给文档,或者使用-e 命令行 ?