Docker Community Forums

Share and learn in the Docker community.

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