-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
64 lines (48 loc) · 1.55 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 使用较小的基础镜像
ARG NODE_VERSION=node:18-alpine
# 生产环境镜像
FROM $NODE_VERSION AS dependency-base
# 安装 pnpm
RUN npm config set registry https://registry.npmmirror.com
RUN npm install -g pnpm
# 设置工作目录
WORKDIR /app
# 复制项目文件
COPY . .
# 使用pnpm安装依赖
RUN pnpm install --frozen-lockfile
# 编译项目
RUN pnpm build
# Stage 2: Production image
FROM $NODE_VERSION AS production
# Create app directory
WORKDIR /app
# Copy built assets from previous stage
COPY --from=dependency-base /app/dist /app/dist
COPY --from=dependency-base /app/package.json /app/package.json
COPY --from=dependency-base /app/pnpm-lock.yaml /app/pnpm-lock.yaml
COPY --from=dependency-base /app/.npmrc /app/.npmrc
RUN npm config set registry https://registry.npmmirror.com
RUN npm install -g pnpm
RUN pnpm install --only=prod
RUN pnpm store prune
# 设置环境变量
## 生产环境
ENV NODE_ENV=production
## 4008为api容器暴露给宿主机的端口, host.docker.internal 表示宿主机
ENV API_URL=http://host.docker.internal:4008
EXPOSE 7777
# 启动项目
CMD ["node", "./dist/server.js"]
# 构建镜像
# docker build -t images-mmf-blog-vite-vue3-ssr -f ./Dockerfile .
# 运行容器
# docker run -d -p 7777:7777 --name container-mmf-blog-vite-vue3-ssr images-mmf-blog-vite-vue3-ssr
# 进入容器
# docker exec -it container-mmf-blog-vite-vue3-ssr /bin/sh
# 停止容器
# docker stop container-mmf-blog-vite-vue3-ssr
# 删除容器
# docker rm container-mmf-blog-vite-vue3-ssr
# 删除镜像
# docker rmi images-mmf-blog-vite-vue3-ssr