nginx docker 文件无法打开文件
nginx docker file cannot open file
我正在写一个 docker 文件到容器中的 运行 openresty nginx。
我的 docker 文件在下面。
FROM ubuntu:latest
ENV PATH="/usr/local/openresty/nginx/sbin:${PATH}"
LABEL info="running open resty on docker container"
RUN apt-get update -y \
&& apt-get install -y wget \
&& wget -qO - https://openresty.org/package/pubkey.gpg | apt-key add - \
&& apt-get -y install software-properties-common \
&& add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" \
&& apt-get update -y \
&& apt-get install -y openresty
RUN mkdir -p /opt/poc
RUN cd /opt/poc \
&& mkdir logs \
&& touch logs/error.log \
&& mkdir conf \
&& cd ../
RUN chmod -R 755 /opt/poc
WORKDIR /opt/poc
ADD ./conf/nginx.conf conf/
EXPOSE 8383
CMD ["nginx", "-p /opt/poc","-c conf/nginx.conf"]
图像构建没有问题。但是当我 运行 docker 时,我收到以下错误消息。
nginx: [alert] could not open error log file: open() "
/opt/poc/logs/error.log" failed (2: No such file or directory)
2017/09/23 03:35:44 [emerg] 1#1: open() " /opt/poc/ conf/nginx.conf"
failed (2: No such file or directory)
而不是 运行ning CMD ["nginx", "-p /opt/poc","-c conf/nginx.conf"]
如果我更改为 CMD $ls
,docker 会列出 conf 和日志目录。所以我不确定我在这里错过了什么。
你的问题很棘手,但我想我已经解决了。
TL;DR
使用这个 CMD
(它在 -p
和 -c
标志中没有 spaces)
CMD ["nginx", "-g", "daemon off;", "-p", "/opt/poc", "-c", "conf/nginx.conf"]
The -g daemon off;
flag brings nginx as a forward process. Otherwise, if this runs as a daemon, your container will just die after nginx started.
长答案
当您将 spaced 字符串添加到任何 CMD
命令时,就会出现问题。在您的情况下,-p /opt/poc
、-c conf/nginx.conf
.
我相信(我需要更多地查看 docs/Docker 源代码来确认)CMD
忽略了您在 [=12] 中输入的两个 "words" 之一=]部分。
正如文档所说,推荐的方法是这样做的:
CMD ["executable","param1","param2"]
因此,在您的情况下,您的 params
正在做 "more" 而不仅仅是作为参数("more" 是当您在那里使用 space 时)。因此,删除间距并将命令拆分为文档所说的解决问题的方式。
提示
我不知道你的用例是什么,但如果可以,请尝试使用社区提供的图像。在此示例中,openresty
的所有者维护图像:
https://hub.docker.com/r/openresty/openresty
此外,他们还提供了一份很好的文档,说明如何 运行 它。
希望对您有所帮助!
我正在写一个 docker 文件到容器中的 运行 openresty nginx。
我的 docker 文件在下面。
FROM ubuntu:latest
ENV PATH="/usr/local/openresty/nginx/sbin:${PATH}"
LABEL info="running open resty on docker container"
RUN apt-get update -y \
&& apt-get install -y wget \
&& wget -qO - https://openresty.org/package/pubkey.gpg | apt-key add - \
&& apt-get -y install software-properties-common \
&& add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" \
&& apt-get update -y \
&& apt-get install -y openresty
RUN mkdir -p /opt/poc
RUN cd /opt/poc \
&& mkdir logs \
&& touch logs/error.log \
&& mkdir conf \
&& cd ../
RUN chmod -R 755 /opt/poc
WORKDIR /opt/poc
ADD ./conf/nginx.conf conf/
EXPOSE 8383
CMD ["nginx", "-p /opt/poc","-c conf/nginx.conf"]
图像构建没有问题。但是当我 运行 docker 时,我收到以下错误消息。
nginx: [alert] could not open error log file: open() " /opt/poc/logs/error.log" failed (2: No such file or directory) 2017/09/23 03:35:44 [emerg] 1#1: open() " /opt/poc/ conf/nginx.conf" failed (2: No such file or directory)
而不是 运行ning CMD ["nginx", "-p /opt/poc","-c conf/nginx.conf"]
如果我更改为 CMD $ls
,docker 会列出 conf 和日志目录。所以我不确定我在这里错过了什么。
你的问题很棘手,但我想我已经解决了。
TL;DR
使用这个 CMD
(它在 -p
和 -c
标志中没有 spaces)
CMD ["nginx", "-g", "daemon off;", "-p", "/opt/poc", "-c", "conf/nginx.conf"]
The
-g daemon off;
flag brings nginx as a forward process. Otherwise, if this runs as a daemon, your container will just die after nginx started.
长答案
当您将 spaced 字符串添加到任何 CMD
命令时,就会出现问题。在您的情况下,-p /opt/poc
、-c conf/nginx.conf
.
我相信(我需要更多地查看 docs/Docker 源代码来确认)CMD
忽略了您在 [=12] 中输入的两个 "words" 之一=]部分。
正如文档所说,推荐的方法是这样做的:
CMD ["executable","param1","param2"]
因此,在您的情况下,您的 params
正在做 "more" 而不仅仅是作为参数("more" 是当您在那里使用 space 时)。因此,删除间距并将命令拆分为文档所说的解决问题的方式。
提示
我不知道你的用例是什么,但如果可以,请尝试使用社区提供的图像。在此示例中,openresty
的所有者维护图像:
https://hub.docker.com/r/openresty/openresty
此外,他们还提供了一份很好的文档,说明如何 运行 它。
希望对您有所帮助!