I've just started looking at Docker
. I have a node app that resizes and image and then sends an SQS
message to aws
when finished. I have managed to create a docker image of my app, copying it from my local machine, but run into the issue that I can't set-up the AWS
varibales that contain my client_id
and client_secret
to send the SQS
message.
Has anyone encountered this issue before?
What commands do I need to write in my dockerfile
to have the aws
variable set-up?
This is my 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
You can use ENV to set up your environment variable in docker. For example.
ENV PORT=9000
ENV LANG=en_US.utf8
However, secret information should not embedded in Dockerfile, you can pass with -e parameter or using a text file and pass to docker by --env-file parameter. You should ignore the text file when summit to SVN or git.
I think the answers regarding the environment variables are good solutions. To offer an alternative, or if you use a file for aws authentication, you could use docker volumes to mount these.
Mount a Host Directory as a Data Volume
In addition to creating a volume using the -v flag you can also mount a directory from your Docker daemon's host into a container.
Note: If you are using Boot2Docker, your Docker daemon only has limited access to your OSX/Windows filesystem. Boot2Docker tries to auto-share your /Users (OSX) or C:\\Users (Windows) directory - and so you can mount files or directories using docker run -v /Users/:/ ... (OSX) or docker run -v /c/Users/:/
Taken from https://docs.docker.com/userguide/dockervolumes/
This solution has the draw back of assuming that the config folder is in a fixed location however.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.