简体   繁体   English

如何码头化 json-server?

[英]How to dockerize json-server?

I'm trying to run json server with docker along with my application in react, but it's not working.我正在尝试将 json 服务器与 docker 以及我的应用程序一起运行,但它不起作用。

My dockerfile and compose settings:我的 dockerfile 和撰写设置:

FROM node:16-alpine
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "run", "dev" ]

version: "3.7"
services:
    react:
        build: .
        ports:
            - 3000:3000

    json-server:
        build: .
        ports:
            - 4000:4000
        command: npm run server

when I run the command docker-compose up, my react application works but the json server shows this in the terminal:当我运行命令 docker-compose up 时,我的反应应用程序工作但 json 服务器在终端中显示:

frontend@0.0.0 server
json-server --watch ./db/dados.json --port 4000

\{^_^}/ hi!
Loading ./db/dados.json
Done

Resources
http://localhost:4000/encomendas
Home
http://localhost:4000
Type s + enter at any time to create a snapshot of the database
Watching...

And nothing happens when I try to fetch the data.当我尝试获取数据时没有任何反应。

console output控制台 output

在此处输入图像描述

Try adding --host flag in your json-server command尝试在您的 json-server 命令中添加--host标志

json-server --watch./db/dados.json --port 4000 --host 0.0.0.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM