Reputation: 18544
I am having problems to build a Docker image of my go service (see error messages at the end). My service code is structured like this:
cmd
- duc-adobe
pkg
- adobe
- common
.gitignore
Dockerfile
go.mod
go.sum
This is my Dockerfile:
# build image
FROM golang:1.12-alpine as builder
RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates
WORKDIR /app
# first download dependencies so that we can utilize the docker cache
COPY go.mod .
COPY go.sum .
RUN go mod download
RUN CGO_ENABLED=0 go build ./cmd/duc-adobe -o /go/bin/app
# executable image
FROM alpine:3.9
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/bin/app /go/bin/app
ENTRYPOINT ["/go/bin/app"]
The problem
The build fails and I do not know how I could fix this problem. This is the output:
Step 1/11 : FROM golang:1.12-alpine as builder
---> 6b21b4c6e7a3
Step 2/11 : RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates
---> Using cache
---> 14b9eb869a9f
Step 3/11 : WORKDIR /app
---> Using cache
---> c2d0df63dc21
Step 4/11 : COPY go.mod .
---> Using cache
---> abd95c3f18eb
Step 5/11 : COPY go.sum .
---> Using cache
---> 3d49861b4f74
Step 6/11 : RUN go mod download
---> Using cache
---> 3cc3c7752c04
Step 7/11 : RUN CGO_ENABLED=0 go build ./cmd/duc-adobe -o /go/bin/app
---> Running in b1034f9c05bb
go: directory /go/bin/app outside available modules
The command '/bin/sh -c CGO_ENABLED=0 go build ./cmd/duc-adobe -o /go/bin/app' returned a non-zero code: 1
I am not sure how in what sense I need to make the go modules accessible or how I could fix this problem?
Upvotes: 1
Views: 4738
Reputation: 31654
See go build usage:
shubuntu1@shubuntu1:~$ go help build
usage: go build [-o output] [-i] [build flags] [packages]
So, you should put -o
in the middle of command, like:
go build -o /go/bin/app ./cmd/duc-adobe
Upvotes: 1