Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
XmchxUp committed Aug 28, 2024
1 parent a77960f commit 26a0e82
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
71 changes: 71 additions & 0 deletions 2024/08/votesystem_docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

> 为什么做此?因为真的有人用的此项目,会来联系我问问题,所以可以考虑部署运行方便。
docker需要配置代理

## Dockerfile

首先就是通过编写Dockerfile来构建image,
内部就是通过maven构建jar包来运行。

maven拉镜像的时候可能也需要代理,或者换源,所以我把maven中的settings.xml配置copy到image里 则可以在里面配置源,设置代理等等。

```Dockerfile
FROM maven:3.8.5-openjdk-11 AS build
WORKDIR /app
COPY pom.xml .
COPY src ./src
COPY settings.xml /usr/share/maven/conf/settings.xml
RUN mvn clean package -DskipTests -X


FROM openjdk:11-jdk
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

```

## Docker-compose

因为需要等待mysql启动完成后再启动service,否则service连接不上mysql,则日志
所以需要加上health check

```yaml
version: "3.8"

services:
db:
image: mysql:5.7
container_name: mysql-db
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: vote
MYSQL_USER: ultraman
MYSQL_PASSWORD: 123456
volumes:
- db_data:/var/lib/mysql
- ./vote.sql:/docker-entrypoint-initdb.d/vote.sql
ports:
- "3306:3306"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-p123456"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s

app:
build: .
container_name: vote-system-app
depends_on:
db:
condition: service_healthy
ports:
- "8080:8080"

volumes:
db_data:

```
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ The best thing to do is have fun.
- [Hobby Projects](/hobby_projects.md)

- **2024-08**
- [6.5840 Lab 2: Key/Value Server](/2024/08/mit65840_lab2.md)
- [为5年前的web项目添加docker构建支持](/2024/08/votesystem_docker.md)
- [6.5840 Lab 2: Key/Value Server](/2024/08/mit65840_lab2.md)
- [数据库中的Query Execution](/2024/08/cmu15445_p2.md)
- [用ts类型系统,实现Rule110(在编译时生成)](/2024/08/ts_type_system_rule110.md)
- [Raylib CGo Demo](/2024/08/raylib_cgo_demo.md)
Expand Down

0 comments on commit 26a0e82

Please sign in to comment.