Ashad001 commited on
Commit
6538091
·
verified ·
1 Parent(s): ede5d44

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -0
Dockerfile CHANGED
@@ -1,21 +1,43 @@
 
1
  FROM golang:1.22.3 AS builder
2
 
 
3
  WORKDIR /app
4
 
 
5
  COPY go.mod go.sum ./
 
 
6
  RUN go mod download
7
 
 
8
  COPY . .
 
 
9
  RUN go build -o main .
10
 
 
 
 
 
11
  FROM alpine:latest
 
 
12
  RUN apk --no-cache add ca-certificates
13
 
 
14
  WORKDIR /root/
15
 
 
16
  COPY --from=builder /app/main .
17
 
 
18
  RUN chmod +x ./main
 
 
 
 
 
19
  EXPOSE 8080
20
 
21
  # Command to run the executable
 
1
+ # Use the official Go image to create a build artifact
2
  FROM golang:1.22.3 AS builder
3
 
4
+ # Set the Current Working Directory inside the container
5
  WORKDIR /app
6
 
7
+ # Copy go mod and sum files
8
  COPY go.mod go.sum ./
9
+
10
+ # Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
11
  RUN go mod download
12
 
13
+ # Copy the source from the current directory to the Working Directory inside the container
14
  COPY . .
15
+
16
+ # Build the Go app
17
  RUN go build -o main .
18
 
19
+ # Debug step: list the contents of the /app directory
20
+ RUN ls -al /app
21
+
22
+ # Use a smaller base image to reduce the final image size
23
  FROM alpine:latest
24
+
25
+ # Install ca-certificates to make HTTPS requests
26
  RUN apk --no-cache add ca-certificates
27
 
28
+ # Set the Current Working Directory inside the container
29
  WORKDIR /root/
30
 
31
+ # Copy the Pre-built binary file from the previous stage
32
  COPY --from=builder /app/main .
33
 
34
+ # Ensure the main executable has execute permissions
35
  RUN chmod +x ./main
36
+
37
+ # Debug step: list the contents of the /root directory
38
+ RUN ls -al /root
39
+
40
+ # Expose port 8080 to the outside world
41
  EXPOSE 8080
42
 
43
  # Command to run the executable