From bc6a82631da11d9a7eff369b566ec8b1dcd9c245 Mon Sep 17 00:00:00 2001 From: Marcel Hintermann Date: Wed, 5 Jun 2024 14:48:04 +0200 Subject: [PATCH] Add support to run it in docker --- Dockerfile | 33 +++++++++++++++++++++++++++++++++ readme.md | 14 ++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..65bd99f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM golang:1.22-alpine3.19 AS builder + +# go mod cache layer +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download + +COPY . ./ +RUN CGO_ENABLED=0 go build -o /out/pastepass main.go + + +FROM alpine:3.19 + +ENV USER=pastepass +ENV UID=1000 +ENV GID=1000 +ENV APP_DIR=/app +ENV DATA_DIR=/data + +RUN apk add --no-cache tini ca-certificates \ + && addgroup -g $GID -S $USER \ + && adduser -u $UID -S -G $USER $USER + +WORKDIR $APP_DIR +COPY --from=builder /out/pastepass . + +RUN mkdir -p $DATA_DIR && chown $UID:$GID $DATA_DIR + +USER $USER +EXPOSE 8008 + +ENTRYPOINT ["/sbin/tini", "--"] +CMD ["./pastepass", "-db-path", "/data/pastepass.db"] \ No newline at end of file diff --git a/readme.md b/readme.md index 3eb904f..2420163 100644 --- a/readme.md +++ b/readme.md @@ -52,6 +52,20 @@ Use the `-h` option to find all options: ./pastepass -h ``` +#### Run with docker + +Build the image + +```bash +git clone https://github.com/v1k45/pastepass.git && cd pastepass +docker build -t pastepass . +``` + +Run the image on the port 10001 with a volume mounted in `path/on/host` to store the database. () +```bash +docker run -p 10001:8008 -v /path/on/host:/data pastepass +``` + #### Options | Option | Description | Default |