deploying a react app + nodejs api's application with docker

Viewed 17

enter image description herei tried to depling my react app to docker file and it just stop after this command "docker build -t docker-expressjs-react ." how can i fixing that? i attached an image of my react app folder to help you understand my files paths thanks for help

enter image description here

dockerFile

FROM node:14 AS ui-build


WORKDIR /usr/app/client/
COPY package*.json ./
RUN npm install
COPY public/ ./public
RUN npm run build
FROM node:14 AS server-build
WORKDIR /usr/app/
COPY --from=ui-build /usr/app/client/build/ .client/build
WORKDIR /usr/app/server/
COPY server/package*.json ./
RUN npm install

COPY server/server.js ./

ENV NODE_ENV=production

EXPOSE 3000
  
CMD ["node", "server.js"]

server file



          let root = path.join(__dirname, '..', 'build');
    if (process.env.NODE_ENV === 'development') {
        app.use(express.static(root));
        app.use('/*', (req, res) => {
            res.sendFile(path.join(__dirname, 'build', 'index.html'));
        });
    } else if (process.env.NODE_ENV === 'production') {
        root = require('path').join(__dirname, '..', 'client', 'build');
        app.use(express.static(root));
        app.use('/*', (req, res) => {
            res.sendFile(path.join(__dirname, '..', 'client', 'build', 'index.html'));
        });
    }
    
    app.use(function(req, res, next) {
        res.header('Access-Control-Allow-Origin', '*');
        res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
        res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
    
        next();
    });

    app.listen(process.env.PORT || port, () => console.log(process.env.PORT || port));

0 Answers
Related