0

How do I make docker run to setns to the network namespace of my choice when starting a container? I want something like --net host mode, but aiming to the namespace of Docker server itself.

Or should I nsenter(1) from within the container started with --net host? Can it be done without making the container overly privileged?

4
  • @PhilipCouling, Host has multiple manually created network namespaces. One of them contains dockers / containerd. Obviously, that is the namespace where --net host containers are started by default. Commented May 3, 2022 at 19:43
  • It is already possible with --privileged --net host container + mounting (-v) the network namespace into the container + nsenter within the container. Maybe Docker supports specifying some additional wrappers while container's is still in host filesystem and hasn't yet dropped privileges. That would make the scheme nicer + remove --privileged from the container itself. Commented May 3, 2022 at 20:00
  • Yeah that's what I'm saying ... the thing responsible for networking prior to dropping privileges is the network driver but i don't think the default one (host) has this functionality built in. The other built-in drivers aren't what you're asking for. It would be especially tricky to implement because container configuration defined when you type docker run ... lives across server reboots. AFAIK network namespaces don't and their numbering is completely lost on reboot. So the driver would need some stable way to configure which namespace you wanted. Commented May 3, 2022 at 20:07
  • Network (and other) namespaces can be mounted to files. Those files can be specified to e.g. nsenter and can have persistent names. I expect the driver to be almost same as host, but accepting an additional argument and doing two additional syscalls: open(2) and setns(2). Commented May 3, 2022 at 20:30

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.