How to run a Docker container using privileged access?

Have you ever run into a situation where you would need to run a container using extended privileges? For instance, say that you are using the dhtest utility which needs the network adapter to run in promiscuous mode, you will need a privileged container. 

This is how I do a simple DHCP test with a container running in privileged mode. Consider the Dockerfile below.

FROM centos:centos8
RUN yum -y install \
  gcc \
  make \
  curl \
  zip \
  git \
  sudo

WORKDIR ~/.

RUN git clone https://github.com/saravana815/dhtest.git

RUN cd dhtest && make && ls -lh dhtest

Build the docker container …

docker build -t test_machine:1 .

Run the docker container in privileged mode.

docker run --privileged --network host test_machine:1 dhtest/dhtest -i eth0 -m 11:22:33:44:55:66

Note: When the operator executes docker run --privileged, Docker will enable access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host. Additional information about running with --privileged is available on the Docker Blog.  That’s all for this post. I hope you learned something new! ☺️

Previous
Previous

How to generate a self-signed certificate using OpenSSL?

Next
Next

How to remove a host key from ssh known_hosts file?