Openresty Docker 容器运行时返回 nginx:无效选项:"/bin/sh"

我尝试使用 openresty:centos 镜像构建一个镜像,并且镜像构建成功,但是尝试用这个镜像运行容器时,容器停止并显示以下信息:

nginx: invalid option: "/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"
点赞
用户9783845
用户9783845

根据 Dockerfile,你应该覆盖 ENTRYPOINT 而不是 CMD。详见 Docker 文档

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/ ENTRYPOINTexec form ( ["executable","param1","param2"],而不是 executable param1 param2)。

2019-07-04 12:40:50