diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..2916eefa3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +node_modules +.git +dist +coverage +logs +*.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..70197fea2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:20-alpine + +WORKDIR /app + +RUN npm install -g pnpm + +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile + +COPY . . +RUN pnpm build + +EXPOSE 3000 + +CMD ["node", "lib/bin.js", "fixtures/db.json"] \ No newline at end of file diff --git a/README.md b/README.md index a70782e7f..ce257e034 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,26 @@ $ curl http://localhost:3000/posts/1 Run `json-server --help` for a list of options +## Run with Docker + +Build the image: + +```shell +docker build -t json-server . +``` + +Run the container: + +```shell +docker run --rm -p 3000:3000 json-server +``` + +API URL: + +```text +http://localhost:3000 +``` + ## Sponsors ✨ ### Gold