Passing file handles to a Docker container

I've been experimenting with various forms of interprocess communication between a server (not a web server) and a client, and things went well -- until I tried putting my client in a Docker container.

I create file handles using nix::unistd::pipe() and use a Unix stream to pass them to my client using the passfd crate. (Thanks to @polachok for a quick fix to a bug.) On the server side I have

let (from_client_raw, to_server_raw) = pipe().unwrap();
let (from_server_raw, to_client_raw) = pipe().unwrap();
let socket = "/tmp/socket/".to_owned() + sock_name;
let listener = UnixListener::bind(socket).unwrap();
let (stream, _) = listener.accept().unwrap();
stream.send_fd(to_server_raw).unwrap());
stream.send_fd(from_server_raw).unwrap();

and the client has

let socket = "/socket/".to_owned() + id;
let stream = UnixStream::connect(socket.clone()).unwrap();

My Docker file is

FROM scratch

COPY target/x86_64-unknown-linux-musl/debug/client /client

ENTRYPOINT ["/client"]

and my Docker command is

docker run --rm -v /tmp/socket:/socket -i client.

That has gotten me past the "file not found" and "invalid mount" errors, but I'm stuck on

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 111, kind: ConnectionRefused, message: "Connection refused" }', src/bin/client.rs:47:54

The permissions on the socket files on the server side are rw-rw-rw-.

Everything works if I run the client with target/debug/client.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.