Adam S
01/20/2023, 5:29 PMdocker.sock
using Ktor. I’ve found KTOR-781 which describes this exact case, and the issue was completed in Ktor 2.0, but I can’t find an example.
Is connecting to docker.sock
with Ktor possible? Is there an example out there somewhere? I’ve given it a go (code in 🧵), but I’m not sure how to get it working.Adam S
01/20/2023, 5:29 PMAdam S
01/20/2023, 5:30 PMAleksei Tirman [JB]
01/20/2023, 6:23 PMfun main() = runBlocking {
val manager = SelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)
val socket = aSocket(manager)
.tcp()
.connect(UnixSocketAddress("/var/run/docker.sock"))
val receiveChannel = socket.openReadChannel()
val sendChannel = socket.openWriteChannel(autoFlush = true)
val send = launch(<http://Dispatchers.IO|Dispatchers.IO>) {
sendChannel.writeStringUtf8("GET /containers/json HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n")
sendChannel.flush()
}
val receive = launch {
while (true) {
val line = receiveChannel.readUTF8Line() ?: break
println(line)
}
}
send.join()
receive.join()
}
Adam S
01/20/2023, 6:34 PM