#Dockerfile go

18 messages · Page 1 of 1 (latest)

molten briar
#

hello guys anyone can help me about docker im deployed on gcp but
terminated: Application failed to start: Failed to create init process: failed to load /app: no such file or directory

FROM golang:1.19

WORKDIR /app

COPY . .

RUN go mod init github.com/nuriansyah/services-logbook-mbkm && go get -d -v ./... && go build -o /app ./cmd/server/main.go

EXPOSE 8080

CMD ["/app"]


manic lichen
#
FROM golang:latest as build

WORKDIR /build
COPY . .
RUN go get -d && \
    CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -extldflags "-static"' -o app .
 
FROM alpine:latest as run
WORKDIR /app
COPY --from=build /build/app .
ENTRYPOINT ["/app/app"]
#

go mod init initializes a new project/module and gives it a name.

autumn whale
manic lichen
#

? it's telling the compiler to disable cgo, as alpine does not have a full glibc (but musl). GOOS is telling the compiler to build for linux, tho not explicitly needed as the compiler knows what platform it is running on.

#

it is not supposed to be defined as container env var

molten briar
#

ahhh solved

tender moss
#
FROM golang:latest as build

WORKDIR /build
COPY go.mod
COPY go.sum
RUN go mod download
COPY . .
RUN go get -d && \
    CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -extldflags "-static"' -o app .
 
FROM alpine:latest as run
WORKDIR /app
COPY --from=build /build/app .
ENTRYPOINT ["/app/app"]

if i am not wrong. with copy go.mod, go.sum and run go mod download, will allow you to use docker cache steps.
so you don't need to download dependencies every time.

manic lichen
#

interesting

#

will test that with our build pipelines

#

we use kaniko for building docker images in a k8s cluster which takes forever. This might help reduce the time by like 20% (1min)

autumn whale
tender moss
#

\

#

just like on documentation

RUN \
    --mount=type=cache,target=/var/cache/apt \
    apt-get update && apt-get install -y git
#

but i looks interesting.

autumn whale
#

Actually my example is in a single line, just discord problem