我想为开源应用程序提供一个简单且简单的Docker容器,它将配置文件的URL作为参数并使用此文件。如何使用远程配置运行Docker和node.js
的Dockerfile是非常直截了当:
FROM phusion/baseimage
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]
RUN curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
RUN apt-get update
RUN apt-get install -y nodejs git
ADD . /src
RUN cd /src; npm install; npm update
ENV NODE_ENV production
CMD ["/usr/bin/node", "/src/gitevents.js"]
我没有发现添加文件时,容器中运行(与地址或入口点),所以我试图去解决它在node.js中的方法:
docker run -e "CONFIG_URL=https://gist.githubusercontent.com/PatrickHeneise/c97ba221495df0cd9a3b/raw/fda1b8cd53874735349c6310a6643e6fc589a404/gitevents_config.js" gitevents
这设置CONFIG_URL
作为我可以在节点中使用的环境变量。但是,我需要下载一个文件,这是异步的,哪种在当前设置中不起作用。
if (process.env.NODE_ENV === 'production') {
var exists = fs.accessSync(path.join(__dirname, 'common', 'production.js'), fs.R_OK);
if (exists) {
config = require('./production');
} else {
// https download, but then `config` is undefined when running the app the first time.
}
}
node.js中没有同步下载,任何建议我怎么能解决这个问题?
我很想让Docker用ADD
或CMD
做一个卷曲下载的工作,但我不确定这是如何工作的?
听起来很有意思。我会尝试的。 – Patrick
我用curl命令写了一个'init.sh'文件,然后运行节点,但是感觉有点脏。通过Dockerfile中的CMD运行脚本。 – Patrick