1.9 KiB
1.9 KiB
Dockerization Task: Lightweight Bun + Hono Container
1. Objective
Create a production-ready Dockerfile and a .dockerignore file for the current Bun + Hono + SQLite application.
2. Performance & Resource Goals
- Concurrency: The container must comfortably handle simultaneous requests (4-5 concurrent connections is the baseline, but it should handle more efficiently). Rely on Bun's native asynchronous event loop.
- Memory Footprint: The image size and runtime memory usage must be minimized.
- Security: Do not run as root if possible, or ensure the environment is restricted.
3. Technical Requirements
A. Base Image
- Use
oven/bun:1-alpineas the base image. - Reason: The Alpine variant is significantly smaller than the Debian-based default, satisfying the low-memory/storage requirement.
B. Build Instructions
- Environment: Set
NODE_ENV=production. - Dependencies: Run
bun install --frozen-lockfile --production. Do not installdevDependencies(like types or test runners) to keep the image small. - Database Directory: Create a dedicated directory for the SQLite database (e.g.,
/app/data). - Volume: Declare a
VOLUMEfor the database directory so data persists after container restarts.
C. Runtime Configuration
- Port: Expose the port (usually 3000).
- Command: Use
bun run src/index.ts(or the entry point file). - Binding: Ensure the Hono app listens on
0.0.0.0(not127.0.0.1orlocalhost), otherwise it will not be accessible outside the container.
D. The .dockerignore file
Create a strict .dockerignore to prevent unnecessary files from increasing the build context size. Exclude:
node_modules*.db(Local database files should not be copied into the image).gitpython-ref*.md
4. Deliverables
Please generate the code for:
Dockerfile.dockerignore