如何在Dockerfile中运行读命令?

我有以下的bash脚本命令

read -r -d '' FILECONTENT <<'ENDFILECONTENT' index index.html; location ~ /\.ht { deny all; } ENDFILECONTENT echo "$FILECONTENT" > /etc/nginx/common.conf 

我如何改变这个,所以它将在一个Dockerfile中成功运行?

我努力了

 ## Common Configuration run read -r -d '' FILECONTENT <<'ENDFILECONTENT' index index.html; location ~ /\.ht { deny all; } ENDFILECONTENT run echo "$FILECONTENT" > /etc/nginx/common.conf 

当我做docker build -t ubuntu1404/djangoapp .时,我得到了以下错误docker build -t ubuntu1404/djangoapp .

 Step 10 : RUN read -r -d '' FILECONTENT <<'ENDFILECONTENT' ---> Running in 69508c5aaed0 /bin/sh: 1: read: Illegal option -d INFO[0062] The command [/bin/sh -c read -r -d '' FILECONTENT <<'ENDFILECONTENT'] returned a non-zero code: 2 

#docker irc频道中的k10dbuild议我使用COPY。

这工作

  1. 有以下几点

     index index.html; location ~ /\.ht { deny all; } 

nginx_configuration/common.conf里面

nginx_configuration/是与Dockerfile相邻的文件夹

  1. 在Dockerfile中input以下内容

## copy the nginx config files COPY ./nginx_configuration/common.conf /etc/nginx/common.conf

  1. 像平常一样运行dockerfile。

     docker build -t ubuntu1404/djangoapp . 

我会按照VonC的说法:把这个脚本放在你的repo中,并在运行时作为一个入口点运行它,这样在开始你的服务之前就会生成你的configuration。