File tree Expand file tree Collapse file tree
docs/serving/samples/hello-world/helloworld-go Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33# https://hub.docker.com/_/golang
44FROM golang:1.13 as builder
55
6- # Copy local code to the container image .
6+ # Create and change to the app directory .
77WORKDIR /app
8+
9+ # Retrieve application dependencies.
10+ # This allows the container build to reuse cached dependencies.
11+ COPY go.* ./
12+ RUN go mod download
13+
14+ # Copy local code to the container image.
815COPY . ./
916
1017# Build the binary.
11- RUN CGO_ENABLED=0 GOOS=linux go build -v -o helloworld- server
18+ RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly - v -o server
1219
1320# Use the official Alpine image for a lean production container.
1421# https://hub.docker.com/_/alpine
@@ -17,7 +24,7 @@ FROM alpine:3
1724RUN apk add --no-cache ca-certificates
1825
1926# Copy the binary to the production image from the builder stage.
20- COPY --from=builder /app/helloworld- server /helloworld- server
27+ COPY --from=builder /app/server /server
2128
2229# Run the web service on container startup.
23- CMD ["/helloworld- server" ]
30+ CMD ["/server" ]
Original file line number Diff line number Diff line change @@ -74,12 +74,19 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-go
7474 # https://hub.docker.com/_/golang
7575 FROM golang:1.13 as builder
7676
77- # Copy local code to the container image .
77+ # Create and change to the app directory .
7878 WORKDIR /app
79+
80+ # Retrieve application dependencies.
81+ # This allows the container build to reuse cached dependencies.
82+ COPY go.* ./
83+ RUN go mod download
84+
85+ # Copy local code to the container image.
7986 COPY . ./
8087
8188 # Build the binary.
82- RUN CGO_ENABLED=0 GOOS=linux go build -v -o helloworld- server
89+ RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly - v -o server
8390
8491 # Use the official Alpine image for a lean production container.
8592 # https://hub.docker.com/_/alpine
@@ -88,10 +95,10 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-go
8895 RUN apk add --no-cache ca-certificates
8996
9097 # Copy the binary to the production image from the builder stage.
91- COPY --from=builder /app/helloworld- server /helloworld- server
98+ COPY --from=builder /app/server /server
9299
93100 # Run the web service on container startup.
94- CMD ["/helloworld- server"]
101+ CMD ["/server"]
95102 ```
96103
971041 . Create a new file, ` service.yaml ` and copy the following service definition
You can’t perform that action at this time.
0 commit comments