27
loading...
This website collects cookies to deliver better user experience
FROM golang:alpine
# Install git.
# Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git
WORKDIR $GOPATH/src/mypackage/myapp/
COPY . .
# Fetch dependencies.
# Using go get.
RUN go get -d -v
# Build the binary.
RUN go build -o /go/bin/hello
ENTRYPOINT ["/go/bin/hello"]
cd
is used in a shell. If the directory doesn't exist it will be created even if it is never used in any other Dockerfile instructions.$GOPATH/src/mypackage/myapp/
. The first .
represents your project directory. The second .
represents the WORKDIR
we set earlier.docker help
docker help $command
to learn more about the command and the options that are available for it. I highly encourage you run this on ever command below. There are many options that you can pass to commands and it will list the aliases that can be used to make the commands shorter and save save some typingdocker build . -t $MYIMAGENAME:$MYIMAGETAG
docker build [OPTIONS] PATH | URL | -
-t
in the command above. If you don't when you search through your images you will only see None
as the image name. docker image ls
docker container ls
docker container ls --all
docker logs $CONTAINERNAME | $CONTAINERID