Json-server: Error with json-server and docker with version 0.14

Created on 21 Jun 2018  路  4Comments  路  Source: typicode/json-server

Hi,

I use [email protected] in a Dockerfile, and it works perfectly with docker !

But with [email protected], i have the following error when i try to request a route :

curl -XGET http://localhost:8080/fake-api/v1/towns                                                                                                           
curl: (56) Recv failure: Connection reset by peer

Here the docker image :

FROM node:9-stretch

RUN npm install -g [email protected]

COPY api /data
WORKDIR /data
VOLUME /data

EXPOSE 8080
ENTRYPOINT ["json-server","--port","8080","--watch","/data/db.json","--routes","/data/routes.json"]

Runned by :

docker build -t fake-server-local -f Dockerfile .
docker run -p 8080:8080 fake-server-local

  \{^_^}/ hi!

  Loading /data/db.json
  Loading /data/routes.json
  Done

  Resources
  http://localhost:8080/countries
  http://localhost:8080/towns

  Other routes
  /v1/* -> /$1
  /fake-api/v1/* -> /$1

  Home
  http://localhost:8080

  Type s + enter at any time to create a snapshot of the database
  Watching...

With a curl request INSIDE the container with "docker exec", the api works ...
And with version 0.12.2, all works.

Thanks !

Most helpful comment

Hey.
Stumbled over the same issue and had a look into the Changelog (https://github.com/typicode/json-server/blob/master/CHANGELOG.md).

The default host address the server was listening to was changed from of 0.0.0.0 to localhost .
With adding --host 0.0.0.0 to your command the server should behave as usual.

All 4 comments

Hey.
Stumbled over the same issue and had a look into the Changelog (https://github.com/typicode/json-server/blob/master/CHANGELOG.md).

The default host address the server was listening to was changed from of 0.0.0.0 to localhost .
With adding --host 0.0.0.0 to your command the server should behave as usual.

Thank you @grenzbotin , it was driving me crazy.

Finally an answer that works

json-server@ ^0.16.1

> 


  \{^_^}/ hi!

  Loading db.json
  Done

  Resources
  http://0.0.0.0:8081/bills
  http://0.0.0.0:8081/categories

  Home
  http://0.0.0.0:8081

  Type s + enter at any time to create a snapshot of the database
  Watching...

dockerfile

FROM alpine

WORKDIR /www

RUN apk add --no-cache nodejs nodejs-npm

COPY package.json package-lock.json ./

COPY db.json ./

RUN npm i --verbose

Linux Docker.

i try to run it as json-server --watch db.json "--port" "8081" "--host" "0.0.0.0"

if i go in browser localhost 8081 doesn't work =/ ping inside container work

Was this page helpful?
0 / 5 - 0 ratings

Related issues

melnikovic picture melnikovic  路  3Comments

zenith77 picture zenith77  路  3Comments

sboudouk picture sboudouk  路  3Comments

shikaan picture shikaan  路  3Comments

casvil picture casvil  路  4Comments