如何 运行 读取 Dockerfile 中的命令?

How to run read command inside a 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 .

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

k10d 在#docker irc 频道建议我使用 COPY。

这有效

  1. 有以下

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

里面nginx_configuration/common.conf

nginx_configuration/是Dockerfile

旁边的文件夹
  1. 在 Dockerfile 中键入以下内容

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

  1. 运行 docker文件正常。

    docker build -t ubuntu1404/djangoapp .
    

我会按照 VonC 所说的那样做:将该脚本放入您的存储库中,并 运行 它作为 运行 时间的入口点,以便它在启动您的服务之前生成您的配置。