Skip to content

Docker 打包 NuxtJS

Docker 镜像加速(Linux 为例)

创建 /etc/docker/daemon.json 的配置文件

json
{
  "registry-mirrors": ["https://registry.docker-cn.com", "https://9zh8kwqg.mirror.aliyuncs.com"]
}
sh
systemctl restart docker

编写 dockerfle

sh
FROM node:10.17.0
MAINTAINER wolfx
ENV NODE_ENV=production
ENV HOST 0.0.0.0
RUN mkdir -p /app
COPY ./ /app
WORKDIR /app
EXPOSE 3000
## RUN npm config set registry https://registry.npm.taobao.org
RUN npm config set registry http://127.0.0.1:8889/repository/npm-proxy/
RUN npm install
RUN npm run build
CMD ["npm", "start"]

如何构建

sh
## build image
docker build -t nuxt-demo ./

如何导出

sh
docker save -o myimages.gz nuxt-demo

如何导入

sh
docker load -i myimages.gz

如何运行

sh
## serve at localhost:8080
docker run -dt -p 8080:3000 nuxt-demo

Version 4.2 (core-1.3.4)