使用docker配置Openresty Hello world

我试着将我的应用容器化,因此我一直在遵循官方的Openresty dockerfile。我的系统OS是Ubuntu 16.04 64位。

我已经使用以下命令拉取了映像。

docker pull openresty/openresty:1.11.2.3-xenial

现在我想使用这个映像,并想要创建一个简单的Hello World应用程序。为此,我已经创建了我的工作目录,创建了一个自定义的dockerfile,并使用它构建了我的自定义映像。最后我运行了一个容器。下面是我的dockerfile内容。

FROM openresty/openresty:1.11.2.3-xenial

EXPOSE 8080
CMD nginx -p `pwd` -c nginx.conf

nginx.conf

worker_processes  1;
error_log stderr notice;
events {
    worker_connections 1024;
}
http {
    include /usr/local/openresty/nginx/conf/mime.types;
    server {
        listen 8888;
        location / {
            default_type text/html;
            content_by_lua_file "app.lua";
        }
    }
}

app.lua

ngx.say('Hello World!')
ngx.exit(200)

构建映像

docker build -t user/openresty .

启动容器

docker run rahul/openresty

当我尝试启动容器时,它会给我一个错误,例如nginx:无效选项:"/bin/sh"。

我不知道我是否朝着正确或错误的方向前进。

更新:

docker run -it -p 8888:80 -v /home/software/docker/openresty:/usr/local/openresty/nginx/html:ro openresty/openresty:1.11.2.3-xenial

我只是使用了这个CLI,它开始显示我创建的index.html。然后我尝试使用以下CLI链接我的自定义nginx.conf,但它不起作用。

docker run -it -p 8888:8888 -v /home/software/docker/openresty:/usr/local/openresty/nginx/html:ro -v /home/software/docker/openresty/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf:ro openresty/openresty:1.11.2.3-xenial

docker run -it -p 8888:8888 -v $(pwd):/app openresty/openresty: 1.11.2.3-xenial -p /app -c nginx.conf

使用下面的命令它开始工作,但是能否有人解释一下呢?

docker run -it -p 8888:8888 -v $(pwd):/app openresty/openresty:1.11.2.3-xenial -p /app -c nginx.conf
点赞
用户4548781
用户4548781

你的端口设置错误,看下面:

EXPOSE 8080
!=
listen 8888;
2019-10-02 21:38:58