<p>There is a utility called <strong>nsenter</strong> in ubuntu. nsenter is a small tool allowing to enter into namespaces. It will enter into your docker container. I want to control the host machine from the docker container. How do I connect the host machine from the container using the nsenter utility?</p>

<p><code>nsenter</code> allows you to join the Linux namespaces of a targeted process id (PID).</p>
<p>First, run a container that shares your hosts PID namespace with <code>--pid=host</code>. The container has to be privileged with <code>--privileged</code>, otherwise executing <code>nsenter</code> will fail with an &quot;Operation not permitted&quot; error. The container is kept running indefinitely by executing <code>tail -f /dev/null</code>.</p>
<pre><code>docker run --pid=host --privileged --name admin-container ubuntu:latest tail -f /dev/null
</code></pre>
<p>Then exec into the container with <code>nsenter</code>, entering the file system, ipc, utc and network namespace of the host machine's very first init process (PID = 1):</p>
<pre><code>docker exec -it admin-container nsenter --target 1 --mount --uts --ipc --net /bin/bash
</code></pre>
<p>Have a look around and you will notice, you are on the host machine.</p>
