logo
0
0
WeChat Login
添加 OpenResty 基础镜像构建配置及 CI/CD 流程

OpenResty with Lua Docker Container

A lightweight Docker container based on Ubuntu 24.04 with OpenResty, Lua 5.4, and lua-resty-http pre-installed and configured.

Features

  • Base OS: Ubuntu 24.04
  • Web Server: OpenResty (Nginx + LuaJIT)
  • Lua Version: Lua 5.4 with development headers
  • HTTP Library: lua-resty-http for HTTP client functionality
  • Pre-configured: Ready-to-use configurations
  • Optimized: Minimal image size with cleaned package lists

Quick Start

Build the Docker Image

docker build -t openresty-lua .

Run the Container

docker run -p 80:80 openresty-lua

The container will start OpenResty and expose it on port 80.

Testing Endpoints

Once the container is running, you can access the following endpoints:

  • Main Page: http://localhost/ - Welcome page with container information
  • Lua Test: http://localhost/lua - Basic Lua functionality test
  • HTTP Library Test: http://localhost/test-http - Verifies lua-resty-http installation

Configuration

OpenResty Configuration Files

  • Main Config: /etc/openresty/nginx.conf - Main OpenResty configuration
  • Server Config: /etc/openresty/conf.d/default.conf - Default server configuration with Lua support

Logs

  • Access Log: /var/log/openresty/access.log
  • Error Log: /var/log/openresty/error.log

Document Root

  • HTML Files: /usr/share/nginx/html/

Development

Adding Lua Libraries

To add additional Lua libraries, you can use the OpenResty Package Manager (opm):

RUN /usr/local/openresty/bin/opm get <author>/<package-name>

Custom Configuration

To add your own configuration:

  1. Mount your configuration files:

    docker run -v /path/to/your/conf:/etc/openresty/conf.d -p 80:80 openresty-lua
  2. Or extend the Dockerfile with your custom configurations using COPY instructions.

Example Lua Code

The container includes sample Lua endpoints in the default configuration:

location /lua { default_type 'text/plain'; content_by_lua_block { ngx.say("Hello, Lua from OpenResty!") } }

Environment Variables

  • DEBIAN_FRONTEND=noninteractive - Prevents interactive prompts during package installation
  • TZ=UTC - Sets timezone to UTC

Installed Components

System Packages

  • wget, curl, gnupg2
  • build-essential, git, vim
  • SSL and compression libraries
  • Lua 5.4 and development headers

OpenResty

  • Full OpenResty distribution from official repository
  • Symbolic links for easier command-line access
  • Pre-configured basic setup

Lua Libraries

  • lua-resty-http - HTTP client library for OpenResty

Port Mapping

The container exposes port 80. Use the following mapping to access it:

docker run -p 8080:80 openresty-lua # Maps container port 80 to host port 8080

Production Usage

For production deployments, consider:

  1. Persistent Storage: Mount volumes for logs and configuration
  2. Resource Limits: Set appropriate memory and CPU limits
  3. Health Checks: Implement health check endpoints
  4. Environment Variables: Use environment-specific configurations
docker run -d \ --name openresty-app \ -p 80:80 \ -v /path/to/logs:/var/log/openresty \ -v /path/to/config:/etc/openresty/conf.d \ --restart unless-stopped \ openresty-lua

Troubleshooting

Check Container Logs

docker logs <container-id>

Access Container Shell

docker exec -it <container-id> /bin/bash

Test OpenResty Configuration

docker exec <container-id> openresty -t

Reload Configuration

docker exec <container-id> openresty -s reload

License

This Docker image is provided as-is for development and testing purposes.