Tao Chen 1 год назад
Родитель
Сommit
4baa8d392e
3 измененных файлов с 52 добавлено и 2 удалено
  1. 4 0
      .dockerignore
  2. 42 0
      Dockerfile.dev
  3. 6 2
      docker-compose.yaml

+ 4 - 0
.dockerignore

@@ -0,0 +1,4 @@
1
+docker-compose.yaml
2
+Dcokerfile
3
+Dcokerfile.dev
4
+data

+ 42 - 0
Dockerfile.dev

@@ -0,0 +1,42 @@
1
+# Use build arguments for Go version and architecture
2
+ARG GO_VERSION=1.23.2
3
+ARG BUILDARCH
4
+
5
+# Stage 1: Build the Go application with swag
6
+FROM golang:${GO_VERSION} AS builder
7
+
8
+# Set up working directory
9
+WORKDIR /app
10
+
11
+# Install dependencies and copy the source code
12
+COPY go.mod ./
13
+RUN go install github.com/swaggo/swag/cmd/swag@latest
14
+RUN go mod download
15
+COPY . .
16
+
17
+#run the build script
18
+RUN chmod +x build.sh && ./build.sh
19
+
20
+# Stage 2: Prepare the final image
21
+FROM alpine:latest
22
+
23
+# Set up working directory
24
+WORKDIR /app
25
+
26
+# Install necessary dependencies
27
+RUN apk add --no-cache tzdata file
28
+
29
+# Copy the built application from the builder stage
30
+COPY --from=builder /app/release /app/
31
+
32
+# Ensure the binary is correctly built
33
+RUN file /app/apimain
34
+
35
+# Set up a volume for persistent data
36
+VOLUME /app/data
37
+
38
+# Expose the necessary port
39
+EXPOSE 21114
40
+
41
+# Define the command to run the application
42
+CMD ["app/apimain"]

+ 6 - 2
docker-compose.yaml

@@ -1,5 +1,8 @@
1 1
 services:
2 2
   rustdesk-api:
3
+    build: 
4
+      context: .
5
+      dockerfile: Dockerfile.dev
3 6
     image: lejianwen/rustdesk-api
4 7
     container_name: rustdesk-api
5 8
     environment:
@@ -11,5 +14,6 @@ services:
11 14
     ports:
12 15
       - 21114:21114
13 16
     volumes:
14
-      - /data/rustdesk/api:/app/data #将数据库挂载出来方便备份
15
-    restart: unless-stopped
17
+      - ./data/rustdesk/api:/app/data #将数据库挂载出来方便备份
18
+    restart: unless-stopped
19
+    command: sleep infnite