Skip to content

How to control a docker VNFs using another docker container

miguelmesquita edited this page Nov 22, 2018 · 1 revision

Mounting the Docker socket

It is possible to manage host containers from within a container by mounting the Docker socket.

Such as:

docker run -it -v /var/run/docker.sock:/var/run/docker.sock ubuntu:latest sh -c "apt-get update ; apt-get install docker.io -y ; bash"

Finding the docker target

root@09e18ee03222:/# docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

09e18ee03222 ubuntu:latest "sh -c 'apt-get upda…" About a minute ago Up About a minute heuristic_goldwasser

776555ee4f93 ubuntu:latest "sh -c 'apt-get upda…" 3 hours ago Up 3 hours recursing_volhard

cfd4a4b2a8fc kylemanna/openvpn "ovpn_run" 24 hours ago Up 24 hours 0.0.0.0:1194->1194/udp amazing_albattani

3aeb62d69536 2c8f4b5e9760 "/usr/sbin/sshd -D" 6 days ago Up 6 days 22/tcp youthful_kepler

Getting target docker id

root@09e18ee03222:/# DOC_ID=$(docker ps -a | grep ovpn | cut -b -13)

Obtain routing table on remote docker

Install netstat on remote docker

root@09e18ee03222:/# docker exec -it $DOC_ID apt install net-tools

Obtain routing table

root@09e18ee03222:/# docker exec -it $DOC_ID netstat -r

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

default 172.17.0.1 0.0.0.0 UG 0 0 0 eth0

172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0