LoginSignup
12

More than 5 years have passed since last update.

docker-composeでjson-serverを使う

Last updated at Posted at 2019-01-21

json-server
https://github.com/typicode/json-server

brewでインストールして使ってみたら便利だったけど、環境を汚したくないのでdockerで動かしたい

https://github.com/clue/docker-json-server
公式にリンクあるこいつをcloneして使ってみたけど繋がらない。なので自分で設定

構成

.
├── docker-compose.yml
└── json-server
    ├── Dockerfile
    └── db.json

Dockerfile

FROM node:10.15.0

RUN npm install -g json-server

WORKDIR /data

EXPOSE 3000

docker-compose.yml

version: '3'
services:
  json-server:
    build: ./json-server
    container_name: test-json-server
    ports:
      - '3000:3000'
    volumes: 
      - ./json-server/db.json:/data/db.json
    command: json-server --watch db.json

繋がらない...

https://github.com/typicode/json-server/issues/811
hostは0.0.0.0にしないとダメだよー

docker-compose.yml

version: '3'
services:
  json-server:
    build: ./json-server
    container_name: test-json-server
    ports:
      - '3000:3000'
    volumes: 
      - ./json-server/db.json:/data/db.json
    command: json-server --watch db.json --host 0.0.0.0

繋がった

http://localhost:3000/
スクリーンショット 2019-01-21 17.18.13.png

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12