Dockerfile は複数行構成ファイルを追加します。

Dockerfile は複数行構成ファイルを追加します。

dockerfileがあり、/etc/nginx/nginx.confに追加されるようにnginx設定ファイルを含めることはできないようです。

私は次の形式を試しました。

RUN cat <<EOT >> /etc/nginx/nginx.conf
user                            www;
worker_processes                auto; # it will be determinate automatically by the number of core

error_log                       /var/log/nginx/error.log warn;
pid                             /var/run/nginx.pid; # it permit you to use /etc/init.d/nginx reload|restart|stop|start

events {
    worker_connections          1024;
}

http {
    include                     /etc/nginx/mime.types;
    default_type                application/octet-stream;
    sendfile                    on;
    access_log                  /var/log/nginx/access.log;
    keepalive_timeout           3000;
    server {
        listen                  80;
        root                    /usr/local/www;
        index                   index.html index.htm;
        server_name             localhost;
        client_max_body_size    32m;
        error_page              500 502 503 504  /50x.html;
        location = /50x.html {
              root              /var/lib/nginx/html;
        }
    }
}
EOT

そして

RUN echo $
'user                            www; \n
worker_processes                auto; # it will be determinate automatically by the number of core \n

error_log                       /var/log/nginx/error.log warn; \n
pid                             /var/run/nginx.pid; # it permit you to use /etc/init.d/nginx reload|restart|stop|start \n

events { \n
    worker_connections          1024; \n
} \n

http { \n
    include                     /etc/nginx/mime.types; \n
    default_type                application/octet-stream; \n
    sendfile                    on; \n
    access_log                  /var/log/nginx/access.log; \n
    keepalive_timeout           3000; \n
    server { \n
        listen                  80; \n
        root                    /usr/local/www; \n
        index                   index.html index.htm; \n
        server_name             localhost; \n
        client_max_body_size    32m; \n
        error_page              500 502 503 504  /50x.html; \n
        location = /50x.html { \n
              root              /var/lib/nginx/html; \n
        } \n
    } \n
}' 
> /etc/nginx/nginx.conf

ただし、これら2つの例のいずれかで次のエラーが発生します。これは、dockerがnginx設定ファイルを独自の変数として処理しようとしているのと少し似ています。

Sending build context to Docker daemon 33.28 kB
Error response from daemon: Unknown instruction: WORKER_PROCESSES

Dockerのバージョンは1.13.1、ビルド07f3374/1.13.1、私が使用するディストリビューションはCentOS Atomic Host 7.1902、dockerの基本イメージはalpinelinuxです。

ありがとう

ベストアンサー1

おすすめ記事