testdir
┣ Dockerfile
┗ data
┗ db.json
$ vim Dockerfile
----
FROM node:20-alpine
RUN npm install -g json-server
WORKDIR /data
CMD ["json-server", "--watch", "db.json", "--port", "3000", "--host", "0.0.0.0"]
----
$ vim db.json
----
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
----
$ docker build -t json-server .
$ docker run --name json-server -p 3000:3000 -v {db.jsonがあるディレクトリのパス}:/data json-server
$ curl http://localhost:3000/posts