bmuschko / gradle-docker-plugin

Gradle plugin for managing Docker images and containers.
https://bmuschko.github.io/gradle-docker-plugin/current/user-guide/
Apache License 2.0
1.23k stars 362 forks source link

[Need help] Build docker image failing on Windows 10 #394

Closed vyshkov closed 7 years ago

vyshkov commented 7 years ago

Hi. I have problems with building docker images on Windows 10.

If i run buildDocker task i get following error:

perating System not officially supported by junixsocket: Windows 10
java.lang.UnsatisfiedLinkError: Could not find library in classpath, tried: [libjunixsocket-windows10-1.8-amd64.so, libjunixsocket-windows10-1.5-amd64.so]
        at org.newsclub.net.unix.NativeUnixSocket.load(NativeUnixSocket.java:81)
        at org.newsclub.net.unix.NativeUnixSocket.<clinit>(NativeUnixSocket.java:112)
        at org.newsclub.net.unix.AFUNIXSocket.<init>(AFUNIXSocket.java:36)
        at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:50)
        at com.github.dockerjava.jaxrs.ApacheUnixSocket.<init>(ApacheUnixSocket.java:51)
        at com.github.dockerjava.jaxrs.UnixConnectionSocketFactory.createSocket(UnixConnectionSocketFactory.java:66)
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:119)
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
        at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:435)
        at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
        at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:701)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
        at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:697)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:448)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:349)
        at com.github.dockerjava.jaxrs.async.POSTCallbackNotifier.response(POSTCallbackNotifier.java:29)
        at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:50)
        at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:24)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
[dockerjava-jaxrs-async-0] ERROR com.github.dockerjava.core.async.ResultCallbackTemplate - Error during callback
java.lang.NoClassDefFoundError: Could not initialize class org.newsclub.net.unix.NativeUnixSocket
        at org.newsclub.net.unix.AFUNIXSocketImpl.connect(AFUNIXSocketImpl.java:134)
        at org.newsclub.net.unix.AFUNIXSocket.connect(AFUNIXSocket.java:97)
        at com.github.dockerjava.jaxrs.ApacheUnixSocket.connect(ApacheUnixSocket.java:62)
        at com.github.dockerjava.jaxrs.UnixConnectionSocketFactory.connectSocket(UnixConnectionSocketFactory.java:74)
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
        at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:435)
        at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
        at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:701)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
        at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:697)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:448)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:349)
        at com.github.dockerjava.jaxrs.async.POSTCallbackNotifier.response(POSTCallbackNotifier.java:29)
        at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:50)
        at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:24)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
:reception:dockerBuildImage FAILED

OR in other project

java.lang.RuntimeException: Library 'junixsocket-native-2.0.4.dll' not found!
        at org.newsclub.net.unix.NarSystem.getLibPath(NarSystem.java:132)
        at org.newsclub.net.unix.NarSystem.loadLibrary(NarSystem.java:36)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.newsclub.net.unix.NativeUnixSocket.<clinit>(NativeUnixSocket.java:35)
        at org.newsclub.net.unix.AFUNIXSocket.<init>(AFUNIXSocket.java:36)
        at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:54)
        at com.github.dockerjava.jaxrs.ApacheUnixSocket.<init>(ApacheUnixSocket.java:51)
        at com.github.dockerjava.jaxrs.UnixConnectionSocketFactory.createSocket(UnixConnectionSocketFactory.java:66)
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:118)
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
        at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:435)
        at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
        at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:701)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
        at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:697)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:448)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:349)
        at com.github.dockerjava.jaxrs.async.POSTCallbackNotifier.response(POSTCallbackNotifier.java:29)
        at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:50)
        at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:24)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
[dockerjava-jaxrs-async-0] ERROR com.github.dockerjava.core.async.ResultCallbackTemplate - Error during callback
java.lang.ExceptionInInitializerError
        at org.newsclub.net.unix.AFUNIXSocket.<init>(AFUNIXSocket.java:36)
        at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:54)
        at com.github.dockerjava.jaxrs.ApacheUnixSocket.<init>(ApacheUnixSocket.java:51)
        at com.github.dockerjava.jaxrs.UnixConnectionSocketFactory.createSocket(UnixConnectionSocketFactory.java:66)
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:118)
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
        at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:435)
        at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
        at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:701)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
        at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:697)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:448)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:349)
        at com.github.dockerjava.jaxrs.async.POSTCallbackNotifier.response(POSTCallbackNotifier.java:29)
        at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:50)
        at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:24)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException
        at org.newsclub.net.unix.NativeUnixSocket.<clinit>(NativeUnixSocket.java:42)
        ... 30 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.newsclub.net.unix.NativeUnixSocket.<clinit>(NativeUnixSocket.java:35)
        ... 30 more
Caused by: java.lang.RuntimeException: Library 'junixsocket-native-2.0.4.dll' not found!
        at org.newsclub.net.unix.NarSystem.getLibPath(NarSystem.java:132)
        at org.newsclub.net.unix.NarSystem.loadLibrary(NarSystem.java:36)
        ... 35 more
:docker-base:buildDocker FAILED

But if i add

docker {
    url =  'http://localhost:2375'
}

to the gradle script - everything fine. Nevertheless i cannot commit that config, so i forced to do this changes every time i clone project or switch branch. Is there any way to make this docker configuration global ? Or define through command line ? I tried gradle clean buildDocker -PdockerServerUrl=http://localhost:2375, but id doesn't help.

Thank you in advance.

cdancy commented 7 years ago

The dockerServerUrl is used only for our functional tests and does not work for normal usage.

Native Windows named pipe support is currently not supported which is why I believe you're seeing the above issue but not when you connect to the tcp port. However, by default and on Windows the plugin should connect to that url by default. Which version of the plugin are you using?

vyshkov commented 7 years ago

@cdancy, ok it seems i we have very old plugin version. Its work fine after update. Thank you!

whgibbo commented 7 years ago

Hi, I have the same issue using 3.0.8:

java.lang.RuntimeException: Library 'junixsocket-native-2.0.4.dll' not found! at org.newsclub.net.unix.NarSystem.getLibPath(NarSystem.java:132) at org.newsclub.net.unix.NarSystem.loadLibrary(NarSystem.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

So I'm using Windows 10 and Docker for Window (hyper-v), is there anything special I need to do to my build script for this to work?

Thanks

cdancy commented 7 years ago

Do you have a reproducible snippet we can look it? I suspect you're trying to connect to a Windows names pipe instead of the tcp port

whgibbo commented 7 years ago

Think you might be onto something..

task buildDocker(type: DockerBuildImage, dependsOn:["build", "copyJar", "createDockerfile"]) { if (System.env.DOCKER_HOST) { url = "$System.env.DOCKER_HOST".replace("tcp", "https") if (System.env.DOCKER_CERT_PATH) { certPath = new File(System.env.DOCKER_CERT_PATH) } } else { url = 'unix:///var/run/docker.sock' } print "Docker: Image filename = ${url}" inputDir = file('build/docker') tag = "${docker_url}/${docker_image_name}:${build_version}".toLowerCase() }

After uninstalling Docker Toolkit and installing Docker for Windows the environment variable DOCKER_HOST was removed.. So just need to obtain the right ip and port I guess?

cdancy commented 7 years ago

If you install native docker on win-10, and expose the tcp port, docker should listen at http://127.0.0.1:2375

whgibbo commented 7 years ago

Yes if you select the option it is working :) Was just wondering why the TLS was enabled by default.. But more a question for Docker For Windows than the plugin.

cdancy commented 7 years ago

@whgibbo yeah I honestly don't know. Don't use windows myself and the only involvement I typically have with it is helping folks such as yourself :)

ricardoaat commented 7 years ago

Docker does listen through the port 2375. The plugin works fine when handling and deploying the docker machines. but it fails to work when i try to debug with the error on the deploy log:

"Cannot retrieve debug connection: java.net.MalformedURLException: unknown protocol: tcp"

Some people have solved this issue changing to port 2375 on dockers over linux or mac. But that's impossible using "Docker for windows" since it doesn't allow us to create machines and expose the port 2376 (secured).

Is it possible for the plugin to work through the not secured port 2375 for debugging?

cdancy commented 7 years ago

@ricardoaat it should work no matter what you're doing. Do you have a reproducible snippet of your gradle file to look at? My hunch is that your URL is somehow off/wrong.

ricardoaat commented 7 years ago

The thing is when the docker container is running (even started through the plugin) i'm able to debug remotely using itellij's remote "Run/Debug Configuration". But the docker plugin fails throwing that message.

The debug port configured at the Deployment tab is 5005

here's my dockerfile:

FROM tomcat

MAINTAINER Ric Arcila <ricardoarcila@outlook.com>

RUN apt-get update && apt-get -y upgrade

WORKDIR /usr/local/tomcat/bin

ENV JPDA_ADDRESS=5005
ENV JPDA_TRANSPORT=dt_socket

COPY build/libs/simple-rest-app.war /usr/local/tomcat/webapps/

EXPOSE 5005 8080
ENTRYPOINT ["catalina.sh", "jpda", "run"]

and my container_settings.json

{
  "_comment": "FOR DETAILED FORMAT LOOK AT https://docs.docker.com/engine/api/v1.22/#create-a-container",
  "AttachStdin": true,
  "OpenStdin": true,
  "HostConfig": {
    "PortBindings":{ "8080/tcp": [{ "HostIp": "0.0.0.0", "HostPort": "18080" }],
      "5050/tcp": [
        {
          "HostIp": "0.0.0.0",
          "HostPort": "5050"
        }
      ]
    }
  }
}

If i run this, it builds the images an runs it: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fd4740d49f48 9b1113d608f0 "catalina.sh jpda run" 17 seconds ago Up 15 seconds 0.0.0.0:5005->5005/tcp, 0.0.0.0:8080->8080/tcp debug_tomcat

but if i try to debug the app at the end i get:

Attaching to container 'debug_tomcat'... Starting container 'debug_tomcat' 'debug_tomcat Dockerfile: Dockerfile' has been deployed successfully. Cannot retrieve debug connection: java.net.MalformedURLException: unknown protocol: tcp

kohlschuetter commented 5 years ago

junixsocket 2.2 now supports Windows 10, please give it a try!