Error received while creating docker for GO - docker

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"]

Related

How to use ssh-keyscan with golang:alpine Docker image?

I am trying to create a Dockerfile using golang:alpine image and ssh-keyscan command, but it is not working. If I use the golang image instead, it works as expected.
Works:
FROM golang
RUN mkdir -p -m 0700 ~/.ssh
RUN ssh-keyscan github.com > /root/.ssh/known_hosts
RUN git config --add --global url."ssh://git#github.com/".insteadOf https://github.com/
WORKDIR /app
ENV GOPRIVATE=github.com/{ommited}/*
COPY go.mod .
COPY go.sum .
RUN --mount=type=ssh go mod download
Does not work:
FROM golang:alpine
RUN apk add --no-cache openssh-client git
RUN mkdir -p -m 0700 ~/.ssh
RUN ssh-keyscan github.com > /root/.ssh/known_hosts
RUN git config --add --global url."ssh://git#github.com/".insteadOf https://github.com/
WORKDIR /app
ENV GOPRIVATE=github.com/{ommited}/*
COPY go.mod .
COPY go.sum .
RUN --mount=type=ssh go mod download
Error:
[9/9] RUN --mount=type=ssh go mod download:
#13 32.30 go: {ommited}#v0.9.3: reading {ommited}/go.mod at revision v0.9.3: git ls-remote -q origin in /go/pkg/mod/cache/vcs/4dc358100530ae5178fe8ee87660554544c37849403335a46d005c2394bf07a5: exit status 128:
#13 32.30 git#github.com: Permission denied (publickey).
#13 32.30 fatal: Could not read from remote repository.
#13 32.30
#13 32.30 Please make sure you have the correct access rights
#13 32.30 and the repository exists.
executor failed running [/bin/sh -c go mod download]: exit code: 1

IBM Code Engine - Docker - 'dependency:go-offline': No such file or directory

I'm trying to get an Hello World app deploy with Code Engine.
I've spend several hours troubleshooting this with no success.
Dockerfile:
FROM eclipse-temurin:17-jdk-focal
WORKDIR /app
RUN ls -la
COPY . .
RUN ls -la
RUN chmod +x ./mvnw dependency:go-offline
#COPY src ./src
CMD ["./mvnw", "spring-boot:run"]
My first error message was as follows:
#11 [6/7] RUN ./mvnw dependency:go-offline
#11 0.132 /bin/sh: 1: ./mvnw: Permission denied
#11 ERROR: process "/bin/sh -c ./mvnw dependency:go-offline" did not complete successfully: exit code: 126
The added chmod +x :
#11 [6/7] RUN chmod +x ./mvnw dependency:go-offline
#0 0.144 chmod: cannot access 'dependency:go-offline': No such file or directory
#11 ERROR: process "/bin/sh -c chmod +x ./mvnw dependency:go-offline" did not complete successfully: exit code: 1
Could anyone provide me some guidance ?
Thank you
Filipe
Issue solved with the precious help of David.
Working solution:
RUN chmod +x mvnw
RUN ./mvnw dependency:go-offline
Thank you

aarch64-alpine-linux-musl/bin/ld: cannot find -lpq

when I build the rust app using the alpine as the base image using this command:
docker build -f ./Dockerfile -t="reddwarf-pro/reddwarf-admin:v.1.0.0" .
show error like this:
#14 222.9 = note: /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: cannot find -lpq
#14 222.9 collect2: error: ld returned 1 exit status
#14 222.9
#14 222.9
#14 223.0 warning: `reddwarf-admin` (bin "reddwarf-admin") generated 1 warning
#14 223.0 error: could not compile `reddwarf-admin` due to previous error; 1 warning emitted
------
executor failed running [/bin/sh -c cargo build --release]: exit code: 101
I have already add the libpq in the alpine image, why still show this error? what should I do to fix this problem? This is the Dockerfile:
# to reduce the docker image size
# build stage
FROM rust:1.54-alpine as builder
WORKDIR /app
COPY . /app
RUN rustup default stable
RUN apk update && apk add --no-cache libpq musl-dev pkgconfig openssl-dev gcc
RUN cargo build --release
# RUN cargo build
# Prod stage
FROM alpine:3.15
WORKDIR /app
ENV ROCKET_ADDRESS=0.0.0.0
# ENV ROCKET_PORT=11014
RUN apk update && apk add --no-cache libpq curl
COPY --from=builder /app/.env /app
COPY --from=builder /app/settings.toml /app
COPY --from=builder /app/target/release/reddwarf-admin /app/
COPY --from=builder /app/Rocket.toml /app
CMD ["./reddwarf-admin"]
I am also tried to add libpq-dev but it seems the alpine did not contains this library.
Perhaps slightly confusingly, the dev version is called postgresql-dev and not libpq-dev in v3.14. (From what I can tell, it was renamed libpq-dev in v3.15).
libpq does indeed install the shared library, but postgresql-dev creates the symbolic link /usr/lib/libpq.so -> libpq.so.5.13 which makes linking succeed.
From man ld:
On systems which support shared libraries, ld may also
search for files other than libnamespec.a. Specifically, on
ELF and SunOS systems, ld will search a directory for a
library called libnamespec.so before searching for one
called libnamespec.a. (By convention, a ".so" extension
indicates a shared library.) Note that this behavior does
not apply to :filename, which always specifies a file called
filename.
That is, the -lname syntax will only search for libname.(a|so), not versioned names.
The dependency you need is:
libpq-dev

Docker - "The command '/bin/sh -c apt-get install nodejs' returned a non-zero code: 100"

I am trying to build a Docker image for my API with the following Dockerfile:
FROM microsoft/dotnet AS build-env
ARG source
RUN echo "source: $source"
WORKDIR /app
RUN apt-get update
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
RUN apt-get install nodejs
RUN node -v
RUN npm -v
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
#Copy everything else & build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/dotnet
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 80
ENTRYPOINT ["dotnet", "API_App.dll"]
However, when I run the docker build command, I keep getting the following error:
Unable to locate package nodejs
The command '/bin/sh -c apt-get install nodejs returned a non-zero code: 100
Can someone tell me why I am getting this error?
Node Version: 8.11.3
npm Version: 5.6.0
You may occasionally experience some cache issues when the live repositories you’re pulling data from have changed.
To fix this, modify the Dockerfile to do a cleanup and update of the sources before you install any new packages.
...
# clean and update sources
RUN apt-get clean && apt-get update
...
This answer is from digitalocean-issue

Docker for golang application

i've golang application which I want to build docker image for it
the application folder called cloud-native-go and the dockerfile is under the root project
Any idea what is wrong here ?
FROM golang:alpine3.7
WORKDIR /go/src/app
COPY . .
RUN apk add --no-cache git
RUN go-wrapper download # "go get -d -v ./..."
RUN go-wrapper install # "go install -v ./..."
#final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /go/bin/app /app
ENTRYPOINT ./app
LABEL Name=cloud-native-go Version=0.0.1
EXPOSE 3000
The error is :
Step 5/12 : RUN go-wrapper download # "go get -d -v ./..."
---> Running in 70c2e00f332d
/bin/sh: go-wrapper: not found
i Build it with
docker build -t cloud-native-go:1.0.0 .
go-wrapper has been deprecated and removed from the images using go version 10 and above. See here.
If you are fine using go v1.9 you can use the following image: golang:1.9.6-alpine3.7.
So your Dockerfile will be:
FROM golang:1.9.6-alpine3.7
WORKDIR /go/src/app
COPY . .
RUN apk add --no-cache git
RUN go-wrapper download # "go get -d -v ./..."
RUN go-wrapper install # "go install -v ./..."
#final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /go/bin/app /app
ENTRYPOINT ./app
LABEL Name=cloud-native-go Version=0.0.1
EXPOSE 3000
FROM golang:alpine
# important!
ENV GO111MODULE=on
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
ENV GOFLAGS=-mod=vendor
ENV APP_USER app
ENV APP_HOME /go/src/microservices
RUN mkdir /nameApp
ADD . /nameApp
WORKDIR /nameApp
//compile your project
RUN go mod vendor
RUN go build
//open the port 8000
EXPOSE 8000
CMD [ "/nameApp/nameApp" ]

Resources