docker-machine configuration with docker-java

648 views
Skip to first unread message

Raquel Pau Fernández

unread,
Sep 25, 2015, 3:51:23 AM9/25/15
to docker-java-dev
Hi,

I am using docker tools and I am working on MacOS. I think that there is no way to configure docker-java to connect with an specific docker-machine. Is it right?

The reason is because in order to access to unix:///var/run/docker.sock I need to be inside the boot2docker (docker-machine ssh default) and to connect the URLs begins with tcp and this protocol is not supported. 

Could you tell me if I am right? Otherwise, is there any work arround?

Regards,

Raquel

marcuslinke

unread,
Sep 25, 2015, 3:59:31 AM9/25/15
to docker-java-dev
You can use http/https protocal to connect to a remote docker daemon. See https://github.com/docker-java/docker-java#programmatic

Hope that helps.

Cheers

Raquel Pau Fernández

unread,
Sep 25, 2015, 4:27:12 AM9/25/15
to docker-java-dev
I have tried with http and https, but it does not work.

My code:


   

DockerClientConfig.DockerClientConfigBuilder builderD = DockerClientConfig

.createDefaultConfigBuilder().withUri("https://192.168.99.100:2376");


DockerClient docker = DockerClientBuilder

.getInstance(builderD)

.build();


ListContainersCmd cmd = docker.listContainersCmd();

List<Container> list = cmd.exec();

for (Container container : list) {

System.out.println(container.getImage());

}



With http the system reports that it can't read the response:

Exception in thread "main" javax.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException

at com.github.dockerjava.jaxrs.connector.ApacheConnector.apply(ApacheConnector.java:490)

at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)

at org.glassfish.jersey.client.JerseyInvocation$3.call(JerseyInvocation.java:705)

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:424)

at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:701)

at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:417)

at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:313)

at com.github.dockerjava.jaxrs.ListContainersCmdExec.execute(ListContainersCmdExec.java:44)

at com.github.dockerjava.jaxrs.ListContainersCmdExec.execute(ListContainersCmdExec.java:1)

at com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec.exec(AbstrSyncDockerCmdExec.java:24)

at com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:33)

at eu.coherentpaas.wrapper.Prova.main(Prova.java:25)

Caused by: org.apache.http.client.ClientProtocolException

at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:188)

at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)

at com.github.dockerjava.jaxrs.connector.ApacheConnector.apply(ApacheConnector.java:443)

... 14 more


Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response

at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:151)

at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)

at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)

at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)

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:483)

at org.apache.http.impl.conn.CPoolProxy.invoke(CPoolProxy.java:138)

at com.sun.proxy.$Proxy19.receiveResponseHeader(Unknown Source)

at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)

at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)

at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:253)

at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194)

at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)

at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)

at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)

... 16 more



With https: 


Exception in thread "main" javax.ws.rs.ProcessingException: org.apache.http.conn.UnsupportedSchemeException: https protocol is not supported

at com.github.dockerjava.jaxrs.connector.ApacheConnector.apply(ApacheConnector.java:490)

at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:246)

at org.glassfish.jersey.client.JerseyInvocation$3.call(JerseyInvocation.java:705)

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:424)

at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:701)

at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:417)

at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:313)

at com.github.dockerjava.jaxrs.ListContainersCmdExec.execute(ListContainersCmdExec.java:44)

at com.github.dockerjava.jaxrs.ListContainersCmdExec.execute(ListContainersCmdExec.java:1)

at com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec.exec(AbstrSyncDockerCmdExec.java:24)

at com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:33)

at eu.coherentpaas.wrapper.Prova.main(Prova.java:25)

Caused by: org.apache.http.conn.UnsupportedSchemeException: https protocol is not supported

at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:99)

at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314)

at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357)

at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218)

at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194)

at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)

at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)

at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)

at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)

at com.github.dockerjava.jaxrs.connector.ApacheConnector.apply(ApacheConnector.java:443)

... 14 more

marcuslinke

unread,
Sep 25, 2015, 4:41:24 AM9/25/15
to docker-java-dev
Maybe your docker daemon doesn't support http for security reasons (at least this is the case with boot2docker). To make it work with https you have to configure your docker cert path.
Either you set the DOCKER_CERT_PATH environment variable or you configure it programmatically. For boot2docker the cert path is $HOME/.boot2docker/certs/boot2docker-vm

Raquel Pau Fernández

unread,
Sep 25, 2015, 5:08:17 AM9/25/15
to docker-java-dev
I have the same error setting the DOCKER_CERT_PATH programmatically with the docker-java api using "http".

marcuslinke

unread,
Sep 25, 2015, 5:15:30 AM9/25/15
to docker-java-dev
Of course this has to match. If you configure a docker cert path but use an http url this will fail.

Raquel Pau Fernández

unread,
Sep 25, 2015, 5:24:02 AM9/25/15
to docker-java-dev
Hi, solved!

For other users. Put an https url (https://192.168.99.100:2376), where the ip corresponds to the docker-machine ip.

To know the certifications folder:

docker-machine inspect default

And there, appear the certification path (directory of the CaCertPath value)

DockerClientConfig.DockerClientConfigBuilder builderD = DockerClientConfig

.createDefaultConfigBuilder()

.withUri("https://192.168.99.100:2376")

.withDockerCertPath(

"/Users/rpau/.docker/machine/certs/");



Reply all
Reply to author
Forward
0 new messages