Skip to content

Commit 0d46dc0

Browse files
committed
Update Go example to use "go.mod"
1 parent 05f7d81 commit 0d46dc0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

golang/content.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ Go (a.k.a., Golang) is a programming language first developed at Google. It is a
88

99
# How to use this image
1010

11-
**Note:** `/go` is world-writable to allow flexibility in the user which runs the container (for example, in a container started with `--user 1000:1000`, running `go get github.com/example/...` will succeed). While the `777` directory would be insecure on a regular host setup, there are not typically other processes or users inside the container, so this is equivilant to `700` for Docker usage, but allowing for `--user` flexibility.
11+
**Note:** `/go` is world-writable to allow flexibility in the user which runs the container (for example, in a container started with `--user 1000:1000`, running `go get github.com/example/...` into the default `$GOPATH` will succeed). While the `777` directory would be insecure on a regular host setup, there are not typically other processes or users inside the container, so this is equivalent to `700` for Docker usage, but allowing for `--user` flexibility.
1212

1313
## Start a Go instance in your app
1414

15-
The most straightforward way to use this image is to use a Go container as both the build and runtime environment. In your `Dockerfile`, writing something along the lines of the following will compile and run your project:
15+
The most straightforward way to use this image is to use a Go container as both the build and runtime environment. In your `Dockerfile`, writing something along the lines of the following will compile and run your project (assuming it uses `go.mod` for dependency management):
1616

1717
```dockerfile
1818
FROM %%IMAGE%%:1.17
1919

20-
WORKDIR /go/src/app
21-
COPY . .
20+
WORKDIR /usr/src/app
21+
22+
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
23+
COPY go.mod go.sum ./
24+
RUN go mod download && go mod verify
2225

23-
RUN go get -d -v ./...
24-
RUN go install -v ./...
26+
COPY . .
27+
RUN go build -v -o /usr/local/bin/app ./...
2528

2629
CMD ["app"]
2730
```

0 commit comments

Comments
 (0)