How to run container in custom netns?

Hi,

I am trying to figure out how to tell docker that I want to run a specifc container in specific network namespace (netns).

For example:

# Add custom netns and configure it:
ip netns add mynetns
...
...

# Run container with this netns
docker run ???

By default docker sets the netns to default:

"SandboxKey": "/var/run/docker/netns/default",

but I can’t find how to override that in favor of mynetns?

Any ideas whether it’s possible? I saw options to share the network namespaces between containers but what I want is to use any netns, in this case the one that is NOT created or managed by docker.

Thanks in advance,
Mateusz

@mkaczanowski did you work it out? thanks

Docker does not support it as far as I know. Here is a tutorial how you could run a container using runc directly:

It also describes the way to set the custom network namespace.

1 Like