运行openresty的docker容器

1.1k 词

编辑作者:糖果

找了些资料,用了一下docker的openrsty的测试。

直接拉取1.9版的Openresty。

docker pull openresty/openresty:1.9.15.1-trusty

将特理机的8080端口和docker的80端口映射。
将不当前config/nginx.conf映射到docker的usr/local/openresty/nginx/conf/nginx.conf,log文件同理。

#!/usr/bin/env bash
docker run -d --name="nginx" -p 8080:80 -v $PWD/config/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf:ro -v $PWD/logs:/usr/local/openresty/nginx/logs openresty/openresty:1.9.15.1-trusty

写一句支持nginx lua的测试脚本。

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    server {
        listen 80;
        location / {
            default_type text/html;
            content_by_lua '
                ngx.say("<p>hello, world</p>")
            ';
        }
    }
}

停止docker,可以stop,也可以kill。

#!/usr/bin/env bash
docker kill nginx && docker rm nginx

登陆docker hub

docker login

提交一个版本

docker commit xxxxxxx  candylab/openrestytest

提交文件到hub上

docker push candylab/openrestytest

还有一个–net选项, --net=host,是直接桥接网卡。
docker run -d --net=host openresty