From c6a4a0645405fd49ecb7b59e608641bbe29ba0f4 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Thu, 23 Mar 2017 15:48:26 -0400 Subject: [PATCH] Bind mount /etc/hosts, /etc/resolv.conf in Run() When we run a command in Run(), since it's sharing the host's network namespace, also have it share the host's DNS settings. Signed-off-by: Nalin Dahyabhai Closes: #34 Approved by: rhatdan --- run.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/run.go b/run.go index b8983d6a..d8586ff8 100644 --- a/run.go +++ b/run.go @@ -113,6 +113,22 @@ func (b *Builder) Run(command []string, options RunOptions) error { return fmt.Errorf("error ensuring working directory %q exists: %v)", b.Workdir, err) } mounts := options.Mounts + boundMounts := []specs.Mount{} + for _, boundFile := range []string{"/etc/hosts", "/etc/resolv.conf"} { + for _, mount := range mounts { + if mount.Destination == boundFile { + // Already have an override for it, so skip this one. + continue + } + } + boundMount := specs.Mount{ + Source: boundFile, + Destination: boundFile, + Type: "bind", + Options: []string{"rbind", "ro"}, + } + boundMounts = append(boundMounts, boundMount) + } for _, specMount := range spec.Mounts { override := false for _, mount := range mounts { @@ -125,7 +141,7 @@ func (b *Builder) Run(command []string, options RunOptions) error { mounts = append(mounts, specMount) } } - spec.Mounts = mounts + spec.Mounts = append(mounts, boundMounts...) specbytes, err := json.Marshal(spec) if err != nil { return err