-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
30 lines (20 loc) · 911 Bytes
/
Copy pathDockerfile
File metadata and controls
30 lines (20 loc) · 911 Bytes
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
FROM golang:1.25.7-alpine AS build
#sets the working directory inside the container to `/app`.All subsequent instructions that use relative paths will be relative to this directory
WORKDIR /app
#Copy go.mod and go.sum files from the local machine to /app inside the container
COPY go.mod go.sum ./
#Download all dependencies
RUN go mod download
#Copy the rest of the source code from the local machine to /app inside the container
COPY . .
#Build the Go app and name the output binary "url_shortner"
RUN go build -o url_shortner .
#multi-stage building, to keep the image final image smaller
FROM alpine:latest
WORKDIR /app
#Copy the Pre-built binary file from the previous stage from /app inside the build container to /app inside the runtime container
COPY --from=build /app/url_shortner .
#Expose port 8080 to the outside world
EXPOSE 8080
#Command to run the executable
CMD ["./url_shortner"]