web项目打包并部署到nginx的镜像,多阶段
FROM node:alpine as builder
WORKDIR '/build'
COPY app ./app
COPY resources ./resources
COPY third_party ./third_party
WORKDIR '/build/app'
RUN npm install
RUN npm rebuild node-sass
RUN npm run build
RUN ls /build/app/dist
FROM nginx
EXPOSE 80
COPY --from=builder /build/app/dist /usr/share/nginx/html
得到APP镜像后,我们可以:
- 直接运行,将容器的80端口映射到8888端口
docker build . -t app
#直接运行
docker run -d -p 8888:80 --name db_nginx app
- 将打包好的静态网页拷贝出来
#将编译好的网页copy出来
id=$(docker create app)
docker cp $id:/usr/share/nginx/html /home/dist/
docker rm -v $id
注意:docker run=docker create + docker start