From 6c46a7560fc115beab266986f852140512a840f9 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Fri, 17 May 2024 22:08:45 +0800 Subject: [PATCH] Add a basic Dockerfile (#179) --- .dockerignore | 3 +++ Dockerfile | 22 ++++++++++++++++++++++ README.md | 17 +++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9a60d44 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules/ +.git/ +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2f53ab2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM node:20-alpine + +RUN apk add --no-cache \ + chromium \ + nss \ + freetype \ + harfbuzz \ + ca-certificates \ + ttf-freefont \ + font-noto-cjk + +WORKDIR /app + +COPY package.json package-lock.json ./ + +RUN npm install + +COPY . ./ + +ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser + +ENTRYPOINT ["/app/bin/index.js"] diff --git a/README.md b/README.md index 56f7fae..54afd80 100644 --- a/README.md +++ b/README.md @@ -108,3 +108,20 @@ mdpdf.convert(options).then((pdfPath) => { * `header` - A sub object which contains some header settings * `height` - Height of the documents header in mm (default 45mm). If you wish to use a header, then this must be set. * `border` - The document borders + +## Docker Usage + +To build the Docker image for mdpdf, use the following command: + +```bash +docker build -t mdpdf . +``` + +To run mdpdf within a Docker container, you can use the following command. This example mounts the current directory to the `/app` directory inside the container and converts `example.md` to `example.pdf`: + +```bash +docker run --rm -v $(pwd):/app mdpdf example.md +``` + +This allows you to use mdpdf without needing to install Node.js or any dependencies on your host machine, only Docker is required. +