|
|
@@ -1,15 +1,41 @@
|
|
|
+package cn.reghao.autodop.common.docker.unixdomain;
|
|
|
+
|
|
|
import jnr.unixsocket.UnixSocket;
|
|
|
import jnr.unixsocket.UnixSocketAddress;
|
|
|
import jnr.unixsocket.UnixSocketChannel;
|
|
|
|
|
|
import java.io.*;
|
|
|
+import java.net.URI;
|
|
|
+import java.net.http.HttpClient;
|
|
|
+import java.net.http.HttpRequest;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
- * @date 2021-10-17 15:33:32
|
|
|
+ * @date 2021-10-17 15:55:46
|
|
|
*/
|
|
|
-public class UnixDomainTest {
|
|
|
+public class UnixDomainSocket {
|
|
|
+ static final String sock = "/var/run/docker.sock";
|
|
|
+ static final File sockFile;
|
|
|
+ static {
|
|
|
+ sockFile = new File(sock);
|
|
|
+ }
|
|
|
+
|
|
|
+ UnixSocket unixSocket() throws IOException {
|
|
|
+ UnixSocketAddress address = new UnixSocketAddress(sockFile);
|
|
|
+ UnixSocketChannel channel = UnixSocketChannel.open(address);
|
|
|
+ return new UnixSocket(channel);
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
+ String uri = "http://v1.24/containers/json";
|
|
|
+ HttpRequest httpRequest = HttpRequest.newBuilder()
|
|
|
+ .GET()
|
|
|
+ .uri(URI.create(uri))
|
|
|
+ .version(HttpClient.Version.HTTP_1_1)
|
|
|
+ .header("Host", "http")
|
|
|
+ .header("Accept", "*/*")
|
|
|
+ .build();
|
|
|
+
|
|
|
// 建立 Unix Socket 连接
|
|
|
File sockFile = new File("/var/run/docker.sock");
|
|
|
UnixSocketAddress address = new UnixSocketAddress(sockFile);
|