Docker 环境
零基础进入Openresty之helloworld
vultr 主机推荐
1 2
| Share Your Link: https://www.vultr.com/?ref=6851639 Give $100, Get $35: https://www.vultr.com/?ref=8955885-8H
|
Docker 环境
1 2 3 4 5
| apt-get -y update;apt-get -y upgrade sudo curl -sS https://get.docker.com/ | sh sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose docker-compose --version
|
环境搭建
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| mkdir -p helloworld/{conf.d,logs,app}
cat >helloworld/conf.d/nginx.conf <<EOG server { listen 8888; location / { default_type text/html; content_by_lua_file "/app/app.lua"; } } EOG
cat >helloworld/app/app.lua <<EOG ngx.say('Hello World! from: QQqun: 397745473') ngx.exit(200) EOG
# cd helloworld && docker build -t vsyour/helloworld . # docker push vsyour/helloworld
|
启动访问
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| # docker run -it -d --name helloworld -p 8080:8080 -v $(pwd):/app vsyour/helloworld
cat >helloworld/docker-compose.yml <<EOG version: '3' services: openresty: container_name: helloworld image: openresty/openresty:alpine restart: always tty: true volumes: - ./app:/app - ./logs:/usr/local/openresty/nginx/logs - ./conf.d/:/etc/nginx/conf.d ports: - "8888:8888" networks: - appnet
networks: appnet: EOG
cd helloworld && docker-compose up -d
|
访问: http://ip:8888