Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update glibc #1342

Closed
ice-cronus opened this issue Jun 15, 2023 · 12 comments
Closed

update glibc #1342

ice-cronus opened this issue Jun 15, 2023 · 12 comments

Comments

@ice-cronus
Copy link

Golang 1.20.5 uses glibc 2.32, while gcr.io/distroless/base-debian11:latest has 2.31

As a result it leads to the error

/app: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /app)
/app: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /app)
@smcguirecn
Copy link

Also occuring to us. Following this topic.

@pebo
Copy link

pebo commented Jun 15, 2023

The 1.20 tag now points to bookworm (debian 12): https://hub.docker.com/_/golang

1.20.5, 1.20, 1, latest:
  1.20.5-bookworm
  1.20.5-windowsservercore-ltsc2022
  1.20.5-windowsservercore-1809

If you want to use go 1.20.5 you could try switching the build image to golang:1.20.5-bullseye or golang:1.20-bullseye

@dlorenc
Copy link
Contributor

dlorenc commented Jun 15, 2023

If you're stuck here, the image at cgr.dev/chainguard/glibc-dynamic works. I just tested with this go file and dockerfile:

main.go:

package main

import (
	"fmt"
	"os/user"
)

func main() {
	u, _ := user.Current()
	fmt.Println("USER: ", u.Username)
}

Dockerfile:

FROM golang
COPY main.go .
RUN CGO_ENABLED=1 go build -o /main main.go

FROM cgr.dev/chainguard/glibc-dynamic
COPY --from=0 main /main
CMD ["/main"]

It works:

dlorenc@MacBook-Pro-5 gotest % docker build . -t cgr
[+] Building 4.0s (11/11) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                           0.0s
 => => transferring dockerfile: 74B                                                                                                                                                                                                                                                            0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                              0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                                0.0s
 => [internal] load metadata for cgr.dev/chainguard/glibc-dynamic:latest                                                                                                                                                                                                                       0.0s
 => [internal] load metadata for docker.io/library/golang:latest                                                                                                                                                                                                                               0.0s
 => CACHED [stage-0 1/3] FROM docker.io/library/golang                                                                                                                                                                                                                                         0.0s
 => CACHED [stage-1 1/2] FROM cgr.dev/chainguard/glibc-dynamic                                                                                                                                                                                                                                 0.0s
 => [internal] load build context                                                                                                                                                                                                                                                              0.0s
 => => transferring context: 190B                                                                                                                                                                                                                                                              0.0s
 => [stage-0 2/3] COPY main.go .                                                                                                                                                                                                                                                               0.0s
 => [stage-0 3/3] RUN CGO_ENABLED=1 go build -o /main main.go                                                                                                                                                                                                                                  2.6s
 => [stage-1 2/2] COPY --from=0 main /main                                                                                                                                                                                                                                                     0.0s
 => exporting to image                                                                                                                                                                                                                                                                         0.0s
 => => exporting layers                                                                                                                                                                                                                                                                        0.0s
 => => writing image sha256:d4ab1187f532bd705d2a445b77333633567bbdde7f2e909b6a5b3c30a69de931                                                                                                                                                                                                   0.0s
 => => naming to docker.io/library/cgr                                                                                                                                                                                                                                                         0.0s
dlorenc@MacBook-Pro-5 gotest % docker run cgr
USER:  root

With this image:

FROM golang
COPY main.go .
RUN CGO_ENABLED=1 go build -o /main main.go

FROM gcr.io/distroless/base
COPY --from=0 main /main
CMD ["/main"]
dlorenc@MacBook-Pro-5 gotest % docker build . -t gcr
[+] Building 0.3s (11/11) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                           0.0s
 => => transferring dockerfile: 220B                                                                                                                                                                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                              0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                                0.0s
 => [internal] load metadata for gcr.io/distroless/base:latest                                                                                                                                                                                                                                 0.2s
 => [internal] load metadata for docker.io/library/golang:latest                                                                                                                                                                                                                               0.0s
 => [stage-0 1/3] FROM docker.io/library/golang                                                                                                                                                                                                                                                0.0s
 => [internal] load build context                                                                                                                                                                                                                                                              0.0s
 => => transferring context: 65B                                                                                                                                                                                                                                                               0.0s
 => CACHED [stage-1 1/2] FROM gcr.io/distroless/base@sha256:73deaaf6a207c1a33850257ba74e0f196bc418636cada9943a03d7abea980d6d                                                                                                                                                                   0.0s
 => CACHED [stage-0 2/3] COPY main.go .                                                                                                                                                                                                                                                        0.0s
 => CACHED [stage-0 3/3] RUN CGO_ENABLED=1 go build -o /main main.go                                                                                                                                                                                                                           0.0s
 => [stage-1 2/2] COPY --from=0 main /main                                                                                                                                                                                                                                                     0.0s
 => exporting to image                                                                                                                                                                                                                                                                         0.0s
 => => exporting layers                                                                                                                                                                                                                                                                        0.0s
 => => writing image sha256:8948bb219ef0beb9669c764dc3e808ae04c6e34ee6b575ae2d8fb3c1891b86ac                                                                                                                                                                                                   0.0s
 => => naming to docker.io/library/gcr                                                                                                                                                                                                                                                         0.0s
dlorenc@MacBook-Pro-5 gotest % docker run gcr
/main: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /main)
/main: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /main)

If you're curious, the chainguard images are built using glibc 2.37: https://github.com/wolfi-dev/os/blob/main/glibc.yaml

@smcguirecn
Copy link

Thanks! Yeah, for now we're just holding golang version back to 1.20.4 ... but I'll try the bookworm thing in the coming days

@chris-harness
Copy link

This is due to the changeover of the golang image builds to use Debian 12, while the Distroless images are all still tagged -debian11. Once -debian12 Distroless image tags are available, you'll be able to simply use the golang image tags like you were using before. Until then you can use the golang:1.20-bullseye to perform your build with the latest go 1.20.x.

@pplmx
Copy link

pplmx commented Jul 27, 2023

This is due to the changeover of the golang image builds to use Debian 12, while the Distroless images are all still tagged -debian11. Once -debian12 Distroless image tags are available, you'll be able to simply use the golang image tags like you were using before. Until then you can use the golang:1.20-bullseye to perform your build with the latest go 1.20.x.

Using golang:1.20-bullseye, still throws error:

Error: Dynamic Linking Error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /app/src/so/libtcpserver.so)

Dockerfile

FROM golang:1.20-bullseye AS so
# build dynamic lib
# ...

FROM node:18-bullseye AS env
# install node packages
# ...

FROM gcr.io/distroless/nodejs18-debian11
# running js app with golang dynamic lib

@pplmx
Copy link

pplmx commented Jul 27, 2023

This is due to the changeover of the golang image builds to use Debian 12, while the Distroless images are all still tagged -debian11. Once -debian12 Distroless image tags are available, you'll be able to simply use the golang image tags like you were using before. Until then you can use the golang:1.20-bullseye to perform your build with the latest go 1.20.x.

Using golang:1.20-bullseye, still throws error:

Error: Dynamic Linking Error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /app/src/so/libtcpserver.so)

Dockerfile

FROM golang:1.20-bullseye AS so
# build dynamic lib
# ...

FROM node:18-bullseye AS env
# install node packages
# ...

FROM gcr.io/distroless/nodejs18-debian11
# running js app with golang dynamic lib

Solution

After the above, build image on Ubuntu 18, which means your docker should be installed Ubuntu 18.

I guess that docker image build will call the glibc from the docker host.

BTW, the above running env is in Ubuntu 2204.

@rayshihUI
Copy link

rayshihUI commented Aug 11, 2023

Use golang: bullseye as build time and base-debian11 as runtime could solve this issue

example yaml:

FROM  golang:1.20.6-bullseye as builder
WORKDIR /go/src/

# For docker buildx multi-platform building
ARG TARGETARCH

# Build path send from build-arg
ARG SOURCE
ARG PKGPATH

# General git information
ARG SERVICENAME
ARG GITTAG
ARG GITBRANCH
ARG GITCOMMIT

# Copy source codes and build
COPY . .

RUN export BUILDDATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") && \
  CGO_ENABLED=1 \
  GOOS=linux \
  GOARCH=${TARGETARCH} \
  go install -mod=vendor \
  -ldflags="-w -s \
  -X $PKGPATH.serviceName=$SERVICENAME \
  -X $PKGPATH.gitTag=$GITTAG \
  -X $PKGPATH.gitCommit=$GITCOMMIT \
  -X $PKGPATH.gitBranch=$GITBRANCH \
  -X $PKGPATH.buildDate=$BUILDDATE \
  " -v ${SOURCE}

# For minimal image
FROM gcr.io/distroless/base-debian11

COPY --from=builder --chown=65532:65532 /go/bin/cmd /opt/

COPY configs/* /opt/

ENTRYPOINT ["/opt/cmd"]
CMD ["--config", "default.json"]

@loosebazooka
Copy link
Member

debian12 images are available for base, base-nossl and static. I believe this should now be working.

@duke-cliff
Copy link

@loosebazooka I am using the latest distroless/cc, it's still using 2.31.

distroless/base is not working for us as well as it does not have libstdc++.so.6

@loosebazooka
Copy link
Member

are you using distroless/cc-debian12 ?

@sankalp-khare
Copy link

sankalp-khare commented Jan 8, 2024

Using distroless base-debian12 (instead of debian11) fixed this for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants