-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: build image and start service with container
- Loading branch information
1 parent
81f3ed3
commit 682cf5d
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 使用 Node 的官方镜像作为基础镜像 | ||
FROM node:20 AS build | ||
|
||
# 设置工作目录 | ||
WORKDIR /app | ||
|
||
# 将 package.json 和 package-lock.json 复制到工作目录 | ||
COPY package*.json ./ | ||
|
||
# 安装项目依赖 | ||
RUN npm install | ||
|
||
# 复制项目文件到工作目录 | ||
COPY . . | ||
|
||
# 构建项目 | ||
RUN npm run build | ||
|
||
# 使用一个轻量级的镜像来运行构建好的应用 | ||
FROM nginx:alpine | ||
|
||
# 将构建好的文件从 build 阶段复制到 nginx 的静态文件目录 | ||
COPY --from=build /app/dist /usr/share/nginx/html | ||
|
||
# 暴露 80 端口 | ||
EXPOSE 80 | ||
|
||
# 启动 nginx | ||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
build: | ||
docker-compose build geetest-demo-build | ||
|
||
run: build clean-container | ||
docker-compose up -d geetest-demo-run | ||
|
||
clean-container: | ||
# stop and remove useless containers | ||
docker-compose down --remove-orphans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: '3.7' | ||
|
||
services: | ||
|
||
geetest-demo-build: | ||
build: | ||
context: . | ||
image: geetest-demo:${IMAGE_TAG:-latest} | ||
|
||
geetest-demo-run: | ||
image: geetest-demo:${IMAGE_TAG:-latest} | ||
command: ["nginx", "-g", "daemon off;"] | ||
ports: | ||
- "30001:80" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters