I have a React app that is connected to a json server which I am trying to run in a docker container. The Dockerfile is as follows:
# base image
FROM node:alpine
# set working directory
WORKDIR '/app'
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install --silent
RUN npm install react-scripts@3.0.1 -g --silent
RUN npm i serve
COPY . .
# start app
CMD ["npm", "start"]
CMD ["node", "server.js"]
CMD ["serve", "-p", "3000", "-s", "."]
The json server is as follows:
var jsonServer = require('json-server')
var server = jsonServer.create()
var router = jsonServer.router(require('./db.js')())
var middlewares = jsonServer.defaults()
server.use(middlewares)
server.use(router)
server.listen(8080, function () {
console.log('JSON Server is running')
})
The problem is when I run
docker run -it -p 3000:3000 personal-react-website
it says my app is running on http://localhost:3000 but when I go there, it is not showing me anything.
I was wondering if anyone could help me figure out why this is not the case?
In my test environment, my React app is on port 3000 and the json server is on 8080 and I just type
npm start
node server.js
any everything works fine.