0

I want to connect to a unix domain socket on the host from within a docker container. Specifically, I run this on the host:

socat - ABSTRACT-LISTEN:/tmp/.X11-unix/X1

And run this in the container:

socat ABSTRACT-CONNECT:/tmp/.X11-unix/X1 -

The expected result is bidirectional communication. But this is met only when the container is run with --net=host:

docker run -it --net=host ubuntu bash

Omitting --net=host gives me ECONNREFUSED (Connection refused):

docker run -it ubuntu bash

Question: Why does --net matter for a unix domain socket connection?

Question: Is it best practice to use --net=host only for allowing unix domain socket connection?

1 Answer 1

1

One of the key selling points of docker is isolation. Using --net=host loosens the network isolation, and while you can definitely use for some cases, I would usually consider it a "code smell", and try other ways first.

In your case, I believe you need to mount any socket you want available in the containers (untested).

$ docker run -it -e DISPLAY -v /tmp/.X11-unix/X1:/tmp/.X11-unix/X1 ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.