Openresty Docker容器在尝试运行时返回nginx:无效选项:“ / bin / sh”

时间:2019-07-04 10:08:21

标签: linux docker nginx lua openresty

我尝试使用openresty:centos构建一个图像,并且该图像已成功构建,但是当尝试使用该图像运行容器时,容器STOP ans显示此消息:

nginx:无效选项:“ / bin / sh”

FROM openresty/openresty:1.11.2.3-centos

RUN yum install openssl-devel -y

RUN /usr/local/openresty/luajit/bin/luarocks install lua-cjson
RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-jwt
RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-redis
RUN /usr/local/openresty/luajit/bin/luarocks install luacrypto
RUN /usr/local/openresty/luajit/bin/luarocks install lualogging
RUN /usr/local/openresty/luajit/bin/luarocks install luaposix
RUN /usr/local/openresty/luajit/bin/luarocks install uuid

RUN PATH=/usr/local/openresty/nginx/sbin:$PATH
RUN export PATH

COPY ./src/api-gw/conf/nginx.conf /usr/local/openresty/nginx/conf

COPY ./src/api-gw/lib/authentication.lua /usr/local/openresty/lualib
COPY ./src/api-gw/lib/logger.lua /usr/local/openresty/lualib
COPY ./src/api-gw/lib/redis.lua /usr/local/openresty/lualib
COPY ./src/api-gw/lib/uses_cases.lua /usr/local/openresty/lualib
COPY ./src/api-gw/lib/utils.lua /usr/local/openresty/lualib

RUN mkdir /home/app

COPY ./src/api-gw/api-gw.lua /home/app

EXPOSE 80

CMD nginx -p /usr/local/openresty/nginx -c nginx.conf

构建映像的命令:

docker build -t openresty_test .

用于运行容器的命令:

docker run -it -p 8888:80 --name img_resty openresty_test

响应:

nginx: invalid option: "/bin/sh"

1 个答案:

答案 0 :(得分:0)

根据Dockerfile,您应该覆盖ENTRYPOINT而不是CMD。有关详细信息,请参见Docker documentation

ENTRYPOINTCMD结合在一起,因此您实际上是在尝试执行:

$ /usr/local/openresty/bin/openresty -g 'daemon off;' /bin/sh -c 'nginx -p /usr/local/openresty/nginx -c nginx.conf'
nginx: invalid option: "/bin/sh"

我还建议您使用CMD / ENTRYPOINT["executable","param1","param2"],而不是executable param1 param2)的 exec格式