Within a Docker network

Next, we will try something a bit advanced by preparing a small system that looks similar to the following diagram. The scenario is that we would like a container started by runf inside another container, wrapper-runf (which is, in reality, a function executor), to connect to some network services running on the same Docker network, test_net:

Figure 9.2: An example of using RunF inside a Docker network

The trick is that we put resolv.conf from the standard Docker Swarm mode as ./rootfs/etc/resolv.conf to make the process inside the nested container be able to resolve all service names on the attached Docker network. Here's the content of resolv.conf:

search domain.name
nameserver 127.0.0.11
options ndots:0

Then we prepare a Dockerfile for the wrapper-runf container:

FROM ubuntu:latest

RUN apt-get update && apt-get install -y curl

WORKDIR /root

COPY ./runf /usr/bin/runf
COPY rootfs /root/rootfs
COPY resolv.conf /root/rootfs/etc/resolv.conf

We can build it normally with the docker build command:

$ docker build -t wrapper-runf .

The following snippet is the preparation for creating a Docker network, attaching nginx to the network, then running a wrapper-runf container with /bin/bash there.

Finally, we start a nested container with runf that connects to nginx:

$ docker network create -d overlay --attachable test_net

$ docker run -d
--network=test_net
--network-alias=nginx
nginx

$ docker run --rm -it
--network=test_net
--privileged
-v /sys/fs/cgroup:/sys/fs/cgroup
wrapper-runf /bin/bash

/ # runf wget http://nginx
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset