Help us understand the problem. What is going on with this article?

docker-composeでjson-serverを使う

More than 1 year has passed since last update.

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

th_
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした