简体   繁体   English

Docker Nodejs 镜像配置

[英]Docker Nodejs Image Config

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.我是 Docker 的新手,我有一个带有 build forder 的 React.js 应用程序( npm run build ),我想将我的应用程序 dockerize 以制作一个容器。

I made a Dockerfile with this config:我用这个配置做了一个 Dockerfile:

FROM node:12-alpine
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD [ "npm", "start" ]

I got those images: dockerimages .我得到了这些图像: dockerimages

Can I dockerize only the build path which is 20MB or the image size is normal?我可以只对 20MB 的构建路径或图像大小正常的构建路径进行 dockerize 吗?

Yes, you can achieve this using multistage Dockerfile , I'm using this for VueJS and Angular .是的,您可以使用多级Dockerfile来实现此目的,我将其用于VueJSAngular

Bonus: you can use NGINX for proxying your requests to your app.奖励:您可以使用 NGINX 将您的请求代理到您的应用程序。

NGINX config and .dockerignore files can be found here . NGINX 配置和.dockerignore文件可以在这里找到。

##### 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

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

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