-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockerfile
46 lines (28 loc) · 832 Bytes
/
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
# FROM golang:1.20-alpine
# RUN apk update && apk add --no-cache git
# WORKDIR /app
# COPY . .
# RUN go mod download
# RUN go build -o app ./bin
# EXPOSE 1234
# CMD ["./app"]
# Multi-stage build: Build binary
FROM golang:latest AS builder
# Set working directory
WORKDIR /app
# Copy file aplikasi ke dalam container
COPY . .
# Build binary aplikasi Golang
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app ./bin
# Stage kedua: Gunakan image Alpine Linux yang ringan
FROM alpine:latest
# Update dan install dependensi yang dibutuhkan
RUN apk --no-cache add ca-certificates
# Set working directory
WORKDIR /app
# Copy binary dari builder stage ke dalam container
COPY --from=builder /app/app .
# Expose port yang digunakan oleh aplikasi
EXPOSE 3000
# Command untuk menjalankan aplikasi
CMD ["./app"]