mirror of https://github.com/knative/docs.git
serving/samples/helloworld-go: simplify and standardize Dockerfile (#508)
This commit is contained in:
parent
382ed049e0
commit
f2518ca45b
|
@ -1,17 +1,25 @@
|
|||
# Start from a Debian image with the latest version of Go installed
|
||||
# and a workspace (GOPATH) configured at /go.
|
||||
FROM golang
|
||||
# Use the offical Golang image to create a build artifact.
|
||||
# This is based on Debian and sets the GOPATH to /go.
|
||||
FROM golang as builder
|
||||
|
||||
# Copy the local package files to the container's workspace.
|
||||
ADD . /go/src/github.com/knative/docs/helloworld
|
||||
# Copy local code to the container image.
|
||||
COPY . /go/src/github.com/knative/docs/helloworld
|
||||
|
||||
# Build the outyet command inside the container.
|
||||
# (You may fetch or manage dependencies here,
|
||||
# either manually or with a tool like "godep".)
|
||||
RUN go install github.com/knative/docs/helloworld
|
||||
|
||||
# Run the outyet command by default when the container starts.
|
||||
ENTRYPOINT ["/go/bin/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
|
||||
|
||||
# Document that the service listens on port 8080.
|
||||
EXPOSE 8080
|
||||
# Copy the binary to the production image from the builder stage.
|
||||
COPY --from=builder /go/bin/helloworld /helloworld
|
||||
|
||||
# Configure and document the service HTTP port.
|
||||
ENV PORT 8080
|
||||
EXPOSE $PORT
|
||||
|
||||
# Run the web service on container startup.
|
||||
CMD ["/helloworld"]
|
||||
|
|
|
@ -59,23 +59,31 @@ following instructions recreate the source files from this folder.
|
|||
[Deploying Go servers with Docker](https://blog.golang.org/docker).
|
||||
|
||||
```docker
|
||||
# Start from a Debian image with the latest version of Go installed
|
||||
# and a workspace (GOPATH) configured at /go.
|
||||
FROM golang
|
||||
# Use the offical Golang image to create a build artifact.
|
||||
# This is based on Debian and sets the GOPATH to /go.
|
||||
FROM golang as builder
|
||||
|
||||
# Copy the local package files to the container's workspace.
|
||||
ADD . /go/src/github.com/knative/docs/helloworld
|
||||
# Copy local code to the container image.
|
||||
COPY . /go/src/github.com/knative/docs/helloworld
|
||||
|
||||
# Build the helloworld command inside the container.
|
||||
# Build the outyet command inside the container.
|
||||
# (You may fetch or manage dependencies here,
|
||||
# either manually or with a tool like "godep".)
|
||||
RUN go install github.com/knative/docs/helloworld
|
||||
|
||||
# Run the helloworld command by default when the container starts.
|
||||
ENTRYPOINT /go/bin/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
|
||||
|
||||
# Document that the service listens on port 8080.
|
||||
EXPOSE 8080
|
||||
# Copy the binary to the production image from the builder stage.
|
||||
COPY --from=builder /go/bin/helloworld /helloworld
|
||||
|
||||
# Configure and document the service HTTP port.
|
||||
ENV PORT 8080
|
||||
EXPOSE $PORT
|
||||
|
||||
# Run the web service on container startup.
|
||||
CMD ["/helloworld"]
|
||||
```
|
||||
|
||||
1. Create a new file, `service.yaml` and copy the following service definition
|
||||
|
|
Loading…
Reference in New Issue