forked from bluebosh/knap-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
28 lines (21 loc) · 977 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
# Use the official Golang image to create a build artifact.
# This is based on Debian and sets the GOPATH to /go.
# https://hub.docker.com/_/golang
FROM golang:1.10 as builder
# Copy local code to the container image.
WORKDIR /go/src/github.com/bluebosh/knap-example
COPY helloworld.go helloworld_test.go .
# Run unit tests
RUN CGO_ENABLED=0 GOOS=linux go test
# Build the code inside the container.
RUN CGO_ENABLED=0 GOOS=linux GOCACHE=off go build -v -o helloworld
# Use a Docker multi-stage build to create a lean production image.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM alpine
# Copy the binary to the production image from the builder stage.
COPY --from=builder /go/src/github.com/bluebosh/knap-example/helloworld /helloworld
# Service must listen to $PORT environment variable.
# This default value facilitates local development.
ENV PORT 8080
# Run the web service on container startup.
CMD ["/helloworld"]