JSONサーバを構築

This commit is contained in:
ry.yamafuji 2025-01-11 03:04:33 +09:00
parent 1fab828a1a
commit 052e900113
4 changed files with 34 additions and 0 deletions

7
Dockerfile Normal file
View File

@ -0,0 +1,7 @@
# AlpineベースのNode.jsイメージを使用
FROM node:18
RUN npm install -g json-server
WORKDIR /usr/local/app

View File

@ -0,0 +1,5 @@
```bash
docker compose build
docker compose up -d
docker compose exec -it json-server bash
```

14
docker-compose.yml Normal file
View File

@ -0,0 +1,14 @@
version: '3.8'
services:
json_server:
build:
context: .
dockerfile: Dockerfile
container_name: json-server
tty: true
stdin_open: true
command: json-server --watch db.json --host 0.0.0.0
volumes:
- ./src:/usr/local/app
ports:
- "3000:3000"

8
src/db.json Normal file
View File

@ -0,0 +1,8 @@
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"user": [
{ "id": 1, "name": "hogehoge", "age": 20 }
]
}