I've been running json-server in a docker container for a while successfully with the following config:
Docker File:
FROM node:alpine
EXPOSE 3000
COPY deploy/conf/mockBackend.json /opt/mockBackend.json
RUN yarn global add json-server
CMD ["json-server", "/opt/mockBackend.json"]
Run command:
docker run -d -p 3000:3000 --name mockbackend mockbackend
Recently this stopped working. I get ERR_CONNECTION_REFUSED
in the browser.
By default json-server binds to 127.0.0.1
, which could cause this issue if this is correct.
I don't know why it worked before, but binding json server to every interface with json-server -H 0.0.0.0 mockBackend.json
makes it work again.
My problem now is that starting json-server
that way in the image manually works fine, but when I change the CMD
line of the Dockerfile to CMD ["json-server", "-H 0.0.0.0", "/opt/mockBackend.json"]
I get the folloing error:
Docker log:
\{^_^}/ hi!
Loading /opt/mockBackend.json
Done
Resources
http:// 0.0.0.0:3000/xxx
http:// 0.0.0.0:3000/yyy
Home
http:// 0.0.0.0:3000
Type s + enter at any time to create a snapshot of the database
events.js:167
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND 0.0.0.0
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:50:26)
Emitted 'error' event at:
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1498:12)
It looks like the json-server
is starting fine, but then exits with the error. Any idea why this only happens when starting the container with the CMD line, but not when running the same json-server
command manually inside the same image?