Cannot load 'libnative-platform.so' using docker container in Ubuntu 16.04

Hello,

I’m executing “gradle -d -version” inside a docker container (CentOS 5.11 32 bits, Gradle 2.8 and Java 1.7. Docker server running over Ubuntu 16.04). I know Gradle is trying to initialize libnative-platform.so. If I look for native library inside cache directory, I can see “.gradle/native/19/linux-i386/libnative-platform.so.lock”. No more files and no more .so libraries.

I’ve got this error:

[developer@57a868b0953b esigp]$ gradle -d -version 15:39:36.201 [DEBUG] [org.gradle.internal.nativeintegration.services.NativeServices] Unable to initialize native-platform. Failure: net.rubygrapefruit.platform.NativeException: Failed to load native library 'libnative-platform.so' for Linux i386. caused by: java.lang.ExceptionInInitializerError caused by: java.io.IOException: Operation not permitted 15:39:36.578 [QUIET] [system.out] 15:39:36.582 [QUIET] [system.out] ------------------------------------------------------------ 15:39:36.583 [QUIET] [system.out] Gradle 2.8

I can’t get more detailed information why library load failed.

If I try to execute “gradle -d”:

[developer@57a868b0953b .ssh]$ gradle -d --stacktrace 15:51:06.706 [DEBUG] [org.gradle.internal.nativeintegration.services.NativeServices] Unable to initialize native-platform. Failure: net.rubygrapefruit.platform.NativeException: Failed to load native library 'libnative-platform.so' for Linux i386. caused by: java.lang.ExceptionInInitializerError caused by: java.io.IOException: Operation not permitted 15:51:06.780 [DEBUG] [org.gradle.internal.nativeintegration.filesystem.services.FileSystemServices] Native-platform file system integration is not available. Continuing with fallback. 15:51:06.783 [DEBUG] [org.gradle.internal.nativeintegration.filesystem.services.FileSystemServices] Using UnsupportedSymlink implementation. 15:51:06.785 [DEBUG] [org.gradle.internal.nativeintegration.filesystem.services.FileSystemServices] Using JDK 7 file service org.gradle.internal.nativeintegration.filesystem.jdk7.PosixJdk7FilePermissionHandler 15:51:08.040 [INFO] [org.gradle.BuildLogger] Starting Build 15:51:08.041 [DEBUG] [org.gradle.BuildLogger] Gradle user home: /home/developer/workspace/.gradle 15:51:08.041 [DEBUG] [org.gradle.BuildLogger] Current dir: /home/developer/.ssh 15:51:08.042 [DEBUG] [org.gradle.BuildLogger] Settings file: null 15:51:08.043 [DEBUG] [org.gradle.BuildLogger] Build file: null 15:51:08.098 [ERROR] [org.gradle.BuildExceptionReporter] 15:51:08.099 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception. 15:51:08.100 [ERROR] [org.gradle.BuildExceptionReporter] 15:51:08.100 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong: 15:51:08.101 [ERROR] [org.gradle.BuildExceptionReporter] Could not open cp_init class cache for initialization script '/home/developer/develop/thirdparty/gradle/gradle/init.d/init.gradle' (/home/developer/workspace/.gradle/caches/2.8/scripts/init_9fzwes3iw44gt0t1fvyj7ybe6/cp_init). 15:51:08.101 [ERROR] [org.gradle.BuildExceptionReporter] > Could not determine a usable local IP for this machine. 15:51:08.102 [ERROR] [org.gradle.BuildExceptionReporter] 15:51:08.102 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is: 15:51:08.104 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.cache.CacheOpenException: Could not open cp_init class cache for initialization script '/home/developer/develop/thirdparty/gradle/gradle/init.d/init.gradle' (/home/developer/workspace/.gradle/caches/2.8/scripts/init_9fzwes3iw44gt0t1fvyj7ybe6/cp_init). 15:51:08.104 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:48) 15:51:08.105 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:28) 15:51:08.105 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultCacheFactory.doOpen(DefaultCacheFactory.java:80) 15:51:08.106 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultCacheFactory.open(DefaultCacheFactory.java:50) 15:51:08.106 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultCacheRepository$PersistentCacheBuilder.doOpen(DefaultCacheRepository.java:138) 15:51:08.107 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultCacheRepository$AbstractCacheBuilder.open(DefaultCacheRepository.java:121) 15:51:08.107 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.groovy.scripts.internal.FileCacheBackedScriptClassCompiler.compile(FileCacheBackedScriptClassCompiler.java:63) 15:51:08.108 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.groovy.scripts.internal.ShortCircuitEmptyScriptCompiler.compile(ShortCircuitEmptyScriptCompiler.java:60) 15:51:08.108 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.groovy.scripts.internal.CachingScriptClassCompiler.compile(CachingScriptClassCompiler.java:41) 15:51:08.109 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.groovy.scripts.DefaultScriptCompilerFactory$ScriptCompilerImpl.compile(DefaultScriptCompilerFactory.java:50) 15:51:08.109 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:122) 15:51:08.110 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.configuration.DefaultInitScriptProcessor.process(DefaultInitScriptProcessor.java:49) 15:51:08.110 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.InitScriptHandler$1.run(InitScriptHandler.java:50) 15:51:08.111 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.Factories$1.create(Factories.java:22) 15:51:08.111 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90) 15:51:08.112 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:57) 15:51:08.112 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.InitScriptHandler.executeScripts(InitScriptHandler.java:46) 15:51:08.113 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:116) 15:51:08.113 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32) 15:51:08.114 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:99) 15:51:08.114 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:93) 15:51:08.114 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90) 15:51:08.115 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62) 15:51:08.115 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:93) 15:51:08.116 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:82) 15:51:08.116 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:94) 15:51:08.117 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28) 15:51:08.117 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35) 15:51:08.118 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43) 15:51:08.118 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28) 15:51:08.118 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:77) 15:51:08.119 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:47) 15:51:08.119 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:51) 15:51:08.120 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:28) 15:51:08.120 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43) 15:51:08.121 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:170) 15:51:08.121 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237) 15:51:08.122 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210) 15:51:08.122 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35) 15:51:08.122 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24) 15:51:08.123 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206) 15:51:08.123 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169) 15:51:08.124 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33) 15:51:08.124 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22) 15:51:08.125 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.Main.doAction(Main.java:33) 15:51:08.125 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) 15:51:08.126 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54) 15:51:08.126 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35) 15:51:08.127 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.launcher.GradleMain.main(GradleMain.java:23) 15:51:08.127 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.RuntimeException: Could not determine a usable local IP for this machine. 15:51:08.128 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.messaging.remote.internal.inet.InetAddressFactory.findLocalBindingAddress(InetAddressFactory.java:115) 15:51:08.128 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.FileLockCommunicator.<init>(FileLockCommunicator.java:38) 15:51:08.129 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.locklistener.DefaultFileLockContentionHandler.getCommunicator(DefaultFileLockContentionHandler.java:153) 15:51:08.129 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.locklistener.DefaultFileLockContentionHandler.reservePort(DefaultFileLockContentionHandler.java:145) 15:51:08.130 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultFileLockManager.lock(DefaultFileLockManager.java:79) 15:51:08.130 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultFileLockManager.lock(DefaultFileLockManager.java:67) 15:51:08.130 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultCacheAccess.open(DefaultCacheAccess.java:86) 15:51:08.131 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:46) 15:51:08.131 [ERROR] [org.gradle.BuildExceptionReporter] ... 48 more 15:51:08.132 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.net.SocketException: Operation not permitted 15:51:08.132 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.messaging.remote.internal.inet.InetAddressFactory.init(InetAddressFactory.java:146)

I have read/write permissions inside GRADLE_USER_HOME directory as “/home/developer/workspace/.gradle/caches/2.8/scripts/init_9fzwes3iw44gt0t1fvyj7ybe6/cp_init” has been generated.

This combination worked for me before (SO, Gradle version, Java version…)!!! The difference is it was working in a docker server over Ubuntu 14.04 (now 16.04). Now I can’t find what’s happening in my environment.

Any suggest?

I really appreciate any help you can provide.

JC

Hello!

I answer myself.

It’s a problem between Docker 1.11.1 and Ubuntu 16.04 when using 32bits binaries (java in my case). It has been reported in docker 1.11.2 release notes: https://github.com/docker/docker/releases

Fix issues when running 32 bit binaries on Ubuntu 16.04 (#22922)

Docker 1.11.2 has been published and now it works.

If you have a previous docker version… add ‘–privileged’ to your “gradle run” command.

Thank you very much,

Hi Juan:
I ran into something very similar; however I AM using Docker 1.11.2 and Ubuntu 16.04. I have installed Gradle 2.10 in a Docker image. I’m building a gradlew job and am getting this message:

2016-07-06T19:43:33.7505620Z ##[section]Starting: gradlew clean :plugin.idea:prepRelease zip
2016-07-06T19:43:33.9706590Z [command]/home/xplatalm/vsts-agent/_work/1/s/gradlew -debug -stacktrace clean :plugin.idea:prepRelease zip
2016-07-06T19:43:33.9890990Z Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
2016-07-06T19:43:34.4693100Z 19:43:34.466 [DEBUG] [org.gradle.internal.nativeintegration.services.NativeServices] Unable to initialize native-platform. Failure: net.rubygrapefruit.platform.NativeException: Failed to load native library ‘libnative-platform.so’ for Linux amd64.
2016-07-06T19:43:34.4702660Z caused by: java.io.IOException: Permission denied

I verified gradlew is using the local copy of ‘libnative-platform.so’ (as there are two copies, one local and one global) and even did a chmod 0777 on the file so it is not really a file permission issue.

Any chance this is related to your issue? Any chance only the 32 bit libs got fixed?

Thanks,
Paul

Hello Paul,

Let’s try one thing… try running your container with the “–privileged” param. Give me feedback!

See you,

Hi Juan:
Yes, running the container with the --privileged option fixes the problem.
Here are my versions:

  • Docker VM is running Ubuntu 16.04.0-LTS (on Azure)
  • Docker version is 1.11.2, build b9f10c9
  • Container OS is Ubuntu 16.04, Gradle installed on container is 2.10
  • Gradle wrapper is being used in build, downloading Gradle 2.2 and using this version for the build, building against Oracle Java 6.
    Thanks,
    Paul

Hi,
I’m not a docker expert, sorry :-(. I think it’s related with “seccomp” policies and linux kernel sandboxing (https://docs.docker.com/engine/security/seccomp/).

It seems gradle (with your versions combination) is performing a restricted call to the kernel (syscall). That’s why it works when you use “–privileged”. Maybe tunning the seccomp profile when running the container helps you and avoids using the unsecure “–privileged” option.

See you,
JC