A simple Go web server that serves markdown files converted to HTML with clean styling.
821
A low memory, <10MB Go web server that serves markdown files converted to HTML.
gomarkdown library.md files from the content/ directory.md extensiongo-markdown-server/
āāā main.go # Main server application
āāā go.mod # Go module dependencies
āāā go.sum # Dependency checksums (generated)
āāā Dockerfile # Docker build configuration (scratch-based)
āāā LICENSE # MIT License
āāā README.md # This file
āāā content/ # Directory for markdown files
ā āāā index.md # Sample homepage content
āāā static/ # Directory for static assets
āāā style.css # CSS styling for HTML output
Install Go dependencies:
go mod tidy
Run the server locally:
go run main.go
Access the server:
Open your browser to http://localhost:8080
The server can be configured using environment variables:
PORT: Server port (default: 8080)CONTENT_DIR: Directory containing markdown files (default: ./content)HTTP_SECURITY_HEADERS: Enable/disable HTTP security headers (default: enable, set to disable to turn off)Example:
PORT=3000 CONTENT_DIR=/path/to/markdown/files HTTP_SECURITY_HEADERS=disable go run main.go
The server includes comprehensive HTTP security headers by default to protect against common web vulnerabilities:
Note: Security headers can be disabled by setting HTTP_SECURITY_HEADERS=disable if needed for compatibility with legacy systems.
The Docker deployment includes advanced security hardening:
1001:1001 inside the containerno-new-privileges security option enabled.md and .css files from the content directoryThis Dockerfile uses a scratch base image, creating an extremely small container with just the Go binary and essential files - no operating system!
Benefits:
Build and run with Docker Compose:
docker-compose up --build
Build and run in background:
docker-compose up --build -d
Run development version:
docker-compose --profile dev up --build
Build the image without running:
docker-compose build
Stop services:
docker-compose down
Build and tag for publishing:
docker-compose build
docker tag mountainpass/go-markdown-server:latest mountainpass/go-markdown-server:v1.0.0
Push to registry:
docker push mountainpass/go-markdown-server:latest
docker push mountainpass/go-markdown-server:v1.0.0
Pull and run from registry:
docker pull mountainpass/go-markdown-server:latest
docker run -p 8080:8080 mountainpass/go-markdown-server:latest
docker build -t mountainpass/go-markdown-server .
docker run -p 8080:8080 mountainpass/go-markdown-server
docker run -p 8080:8080 -v /path/to/your/content:/content mountainpass/go-markdown-server
docker run -p 3000:3000 -e PORT=3000 -e CONTENT_DIR=/content mountainpass/go-markdown-server
Add markdown files to the content/ directory
Access files via clean URLs:
http://localhost:8080/ ā serves content/index.mdhttp://localhost:8080/about ā serves content/about.mdhttp://localhost:8080/docs/setup ā serves content/docs/setup.mdStatic assets can be placed in the static/ directory and accessed via /static/ URL path
Auto-generated content: If the content directory is empty, a sample index.md is automatically created
To modify the server:
main.go for server logic changesstatic/style.css for styling changescontent/ directoryThe server automatically extracts page titles from the first H1 header (# Title) in each markdown file.
The scratch-based Docker image provides:
Note: The scratch approach works because Go can compile to a statically-linked binary that includes all dependencies. This is ideal for microservices and containerized deployments.
This project is open source and available under the MIT License.
Content type
Image
Digest
sha256:b835d0c98ā¦
Size
5.5 MB
Last updated
over 1 year ago
docker pull mountainpass/go-markdown-server