Docker Nodejs Image Config

后端 未结 1 919
名媛妹妹
名媛妹妹 2020-12-20 06:01

I am new to Docker, I have a React.js app with the build forder (npm run build), I want to dockerize my app to make a container.

I made a Dockerfile with

相关标签:
1条回答
  • 2020-12-20 06:21

    Yes, you can achieve this using multistage Dockerfile, I'm using this for VueJS and Angular.

    Bonus: you can use NGINX for proxying your requests to your app.

    NGINX config and .dockerignore files can be found here.

    ##### 01- Build app
    FROM node:lts-alpine as node
    LABEL author="Waqas Dilawar"
    WORKDIR /app
    COPY package.json ./
    RUN npm install
    COPY . .
    RUN npm run build
    
    ##### 02- Run NGINX using build from step 01
    FROM nginx:alpine
    VOLUME /var/cache/nginx
    COPY --from=node /app/dist /usr/share/nginx/html
    COPY ./config/nginx.conf /etc/nginx/conf.d/default.conf
    
    0 讨论(0)
提交回复
热议问题