简体   繁体   中英

Error received while creating docker for GO

I need to develop a lab for my presentation. I am not much aware about docker. When I am trying to follow instruction to build up docker image I am facing below error please help.

 => ERROR [10/10] RUN go install -v ./...                                                                          1.1s
------
 > [10/10] RUN go install -v ./...:
#14 0.490 golang.org/x/text/transform
#14 0.496 golang.org/x/net/http2/hpack
#14 0.497 golang.org/x/text/unicode/bidi
#14 0.504 github.com/go-sql-driver/mysql
#14 0.523 golang.org/x/text/unicode/norm
#14 0.584 golang.org/x/text/secure/bidirule
#14 0.672 golang.org/x/net/idna
#14 0.735 golang.org/x/net/http/httpguts
#14 0.749 golang.org/x/net/http2
#14 1.060 golang.org/x/net/http2/h2c
#14 1.074 # golang.org/x/net/http2/h2c
#14 1.074 ../golang.org/x/net/http2/h2c/h2c.go:159:13: undefined: io.ReadAll
#14 1.074 ../golang.org/x/net/http2/h2c/h2c.go:160:11: undefined: io.NopCloser
------
executor failed running [/bin/sh -c go install -v ./...]: exit code: 2
ERROR: Service 'backend' failed to build : Build failed

The backend.dockerfile is:

FROM golang:1.15-alpine

RUN apk add --no-cache git
WORKDIR /go/src/app
COPY src/*.go ./
COPY src/*.htm ./
COPY src/static/*.css ./static/
COPY src/static/*.png ./static/
COPY src/static/cover/*.jpg ./static/cover/

RUN go get -d -v ./...
RUN go install -v ./...

CMD ["app"]

Try to use this version

FROM golang:1.17-alpine as build-env

# Set environment variable
ENV APP_NAME app
ENV CMD_PATH main.go

RUN apk add --no-cache git
WORKDIR $GOPATH/src/$APP_NAME
COPY src/*.go ./

COPY src/*.htm ./
COPY src/static/*.css ./static/
COPY src/static/*.png ./static/
COPY src/static/cover/*.jpg ./static/cover/

# Run Stage
FROM alpine:3.14

# Set environment variable
ENV APP_NAME app

# Copy only required data into this image

COPY --from=build-env /$APP_NAME .

RUN go get -d -v ./...
RUN go install -v ./...

EXPOSE 8081

CMD ["app"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM