Docker 打包 NuxtJS

# Docker 镜像加速(Linux 为例)

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

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

# 编写 dockerfle

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"]
1
2
3
4
5
6
7
8
9
10
11
12
13

# 如何构建

# build image
docker build -t nuxt-demo ./
1
2

# 如何导出

docker save -o myimages.gz nuxt-demo
1

# 如何导入

docker load -i myimages.gz
1

# 如何运行

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