keeganwitt / docker-gradle

Docker images with Gradle
https://hub.docker.com/_/gradle/
Apache License 2.0
147 stars 73 forks source link

Graal images failed to load native library 'libnative-platform.so' for Linux amd64. #255

Closed XhstormR closed 1 year ago

XhstormR commented 1 year ago

When I use the default root user, I can run gradle normally, but when I switch to the gradle user, the program fails to run.

You can see that the permissions of the /home/gradle/.gradle folder belong to root, and the gradle user has no permissions.

 ❯ docker run -u 1000 --rm -it gradle:graal bash -c  'id && pwd && ls -la && gradle --version'                                                                   (base)
uid=1000(gradle) gid=1000(gradle) groups=1000(gradle)
/home/gradle
total 12
drwxr-x--- 1 gradle gradle   54 Aug 15 23:22 .
drwxr-xr-x 1 root   root     12 Aug 15 23:20 ..
-rw-r--r-- 1 gradle gradle  220 Jan  6  2022 .bash_logout
-rw-r--r-- 1 gradle gradle 3771 Jan  6  2022 .bashrc
drwxr-xr-x 1 root   root      0 Aug 15 23:20 .gradle
-rw-r--r-- 1 gradle gradle  807 Jan  6  2022 .profile

FAILURE: Build failed with an exception.

* What went wrong:
Gradle could not start your build.
> Could not initialize native services.
   > Failed to load native library 'libnative-platform.so' for Linux amd64.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

The default latest image works fine.

 ❯ docker run -u 1000 --rm -it gradle:latest bash -c  'id && pwd && ls -la && gradle --version'                                                                   (base)
uid=1000(gradle) gid=1000(gradle) groups=1000(gradle)
/home/gradle
total 12
drwxr-x--- 1 gradle gradle    0 Jul 25 23:50 .
drwxr-xr-x 1 root   root     12 Jul 25 23:50 ..
-rw-r--r-- 1 gradle gradle  220 Jan  6  2022 .bash_logout
-rw-r--r-- 1 gradle gradle 3771 Jan  6  2022 .bashrc
drwxr-xr-x 1 gradle gradle    0 Jul 25 23:50 .gradle
-rw-r--r-- 1 gradle gradle  807 Jan  6  2022 .profile

Welcome to Gradle 8.2.1!

Here are the highlights of this release:
 - Kotlin DSL: new reference documentation, assignment syntax by default
 - Kotlin DSL is now the default with Gradle init
 - Improved suggestions to resolve errors in console output
 - Reduced sync memory consumption

For more details see https://docs.gradle.org/8.2.1/release-notes.html

------------------------------------------------------------
Gradle 8.2.1
------------------------------------------------------------

Build time:   2023-07-10 12:12:35 UTC
Revision:     a38ec64d3c4612da9083cc506a1ccb212afeecaa

Kotlin:       1.8.20
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          17.0.8 (Eclipse Adoptium 17.0.8+7)
OS:           Linux 6.4.8-orbstack-00059-g106c60a3471f amd64
keeganwitt commented 1 year ago

Yea, I had this problem during testing, but I thought I fixed it.

What's strange is when I build the image locally, it works, but using the image that the Docker Library Jenkins built, it doesn't 🤔

keeganwitt commented 1 year ago

Ah, they're different contents.

$ docker run --rm -u gradle myLocalGradleImage ls -la .gradle      
total 8
drwxr-xr-x 2 root   root   4096 Aug 15 23:20 .
drwxr-x--- 1 gradle gradle 4096 Aug 15 23:22 ..

$ docker run --rm -u gradle gradle:17-graal ls -la .gradle  
total 20
drwxr-xr-x 4 gradle gradle 4096 Aug 16 14:04 .
drwxr-x--- 1 gradle gradle 4096 Aug 16 13:47 ..
drwxr-xr-x 4 gradle gradle 4096 Aug 16 14:04 native

and that directory is a volume, that's why.

keeganwitt commented 1 year ago

Official images PR: https://github.com/docker-library/official-images/pull/15214

XhstormR commented 1 year ago

Weird, still get this issues after pull latest graal images.

 ❯ docker images
REPOSITORY                            TAG       IMAGE ID       CREATED        SIZE
gradle                                graal     e5e4eed24da7   12 hours ago   1.14GB
keeganwitt commented 1 year ago

Weird, still get this issues after pull latest graal images.

 ❯ docker images
REPOSITORY                            TAG       IMAGE ID       CREATED        SIZE
gradle                                graal     e5e4eed24da7   12 hours ago   1.14GB

Maybe make sure you're not using a cached image? docker run --rm gradle@sha256:48d1da617a3647cf58dc7e9d2e8bacf8815fac838133680d3014dd01f2696671 gradle --version is what I got from docker pull gradle:graal. https://hub.docker.com/layers/library/gradle/graal/images/sha256-333cbc28fc9ad3413ebb120e04124b533cab8175af643ede3c83614f7d6023d6?context=explore is the sha Docker Hub shows is the latest (docker run --rm gradle@sha256:333cbc28fc9ad3413ebb120e04124b533cab8175af643ede3c83614f7d6023d6 gradle --version). They both work for me.

My tests were done with amd64 images. Docker version 24.0.5 on Docker Desktop 4.22.0.