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

金·斯塔克斯(Kim Stacks)

我有以下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
金·斯塔克斯(Kim Stacks)

#docker irc频道中的k10d建议我使用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. 正常运行dockerfile。

    docker build -t ubuntu1404/djangoapp .
    

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章