Search code examples
dockernetworkingcentoscentos7ifconfig

Add virtual NIC in CentOS docker container


I'm trying to add a dummy network adapter to a docker container. I.e. not trying to connect to any actual interfaces on a local machine.

I've tried running ifconfig but to no avail:

[root@240ae570546a /]# ifconfig eth0:1 10.0.0.10/24 up SIOCSIFADDR: Operation not permitted SIOCSIFFLAGS: Operation not permitted SIOCSIFFLAGS: Operation not permitted SIOCSIFNETMASK: Operation not permitted

I've also tried adding a configuration file to /etc/sysconfig/network-scripts/ when building my docker container, but this doesn't seem to do the trick either.

My container is built on top of centos:7. How do I add a virtual NIC to my container?


Solution

  • It seems that I needed to run the docker container with the --cap-add=NET_ADMIN command line param:

    docker run --cap-add=NET_ADMIN -it my_container /bin/bash