From e03a674222221f6886c441e292b47a03f4e3d811 Mon Sep 17 00:00:00 2001 From: Florian Walther Date: Fri, 1 May 2026 18:46:12 +0200 Subject: [PATCH] added Dockerfile --- .dockerignore | 21 ++++++++++++++++++++ Dockerfile | 24 +++++++++++++++++++++++ README.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b2024b5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,21 @@ +# Binaries +mdhost + +# IDE +.idea +.vscode +*.swp + +# OS +.DS_Store +Thumbs.db + +# Logs +*.log + +# Data +posts/ +data/ + +# Test +*_test.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cafdaa3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM golang:1.26-alpine AS builder + +WORKDIR /app + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy source code +COPY . . + +# Build statically +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags='-w -s' -o mdhost . + +# Final scratch image +FROM scratch + +# Copy binary from builder +COPY --from=builder /app/mdhost /mdhost + +# Run the application - directories will be bind-mounted from host +CMD ["/mdhost"] diff --git a/README.md b/README.md index 6370b90..2222b56 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,59 @@ The creation timestamp is stored in the file's `CreatedAt` field and persists ac | GET | `/logout` | Clear session | | GET | `/claim` | Claim anonymous files (auto-handled in register) | +## Docker + +### Build the Image + +```bash +docker build -t mdhost . +``` + +### Run with Docker + +The `data` and `posts` directories are designed to be bind-mounted from the host filesystem for persistence: + +```bash +# Create host directories for persistent data +mkdir -p ~/mdhost-data ~/mdhost-posts + +# Run the container with bind mounts +docker run -d \ + --name mdhost \ + -p 8080:8080 \ + -v ~/mdhost-posts:/posts \ + -v ~/mdhost-data:/data \ + mdhost +``` + +The application will be available at `http://localhost:8080`. + +- **`/posts`** - Markdown files are stored here (bind-mounted from host) +- **`/data`** - Metadata (users, sessions, file metadata) is stored here as `data.json` (bind-mounted from host) + +### Docker Compose + +Create a `docker-compose.yml`: + +```yaml +version: '3.8' +services: + mdhost: + build: . + ports: + - "8080:8080" + volumes: + - ./posts:/posts + - ./data:/data + restart: unless-stopped +``` + +Then run: + +```bash +docker compose up -d +``` + ## Dependencies - Go 1.26+