Docker Node.js映像配置 [英] Docker Nodejs Image Config

查看:122
本文介绍了Docker Node.js映像配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手,我有一个带有构建命令的React.js应用程序( npm run build ),我想对我的应用程序进行Docker化以创建一个容器。

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.

我使用以下配置制作了一个Dockerfile:

I made a Dockerfile with this config:

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

我得到了这些图像: dockerimages

我可以仅对20MB或镜像大小正常的构建路径进行dockerize吗?

Can I dockerize only the build path which is 20MB or the image size is normal?

推荐答案

是的,您可以使用多阶段 Dockerfile 实现此目的,我将其用于 VueJS ,并且角度

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

奖金::您可以使用NGINX将请求代理到您的应用。

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

NGINX配置和 .dockerignore 文件可在此处找到>。

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

这篇关于Docker Node.js映像配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆