From d4bec0dd9a04642cf3c838b6c7a05694f9adce11 Mon Sep 17 00:00:00 2001 From: Paul Furtado Date: Fri, 31 Mar 2017 05:58:00 -0400 Subject: [PATCH] Add --user root to docker exec command (#389) * Add --user root to docker exec command If containers were run with their user set to something other than root, docker exec will exec the command in the container as that user by default. Unfortunately, this causes many package manager commands to fail. This commit adds --user root to the docker exec command so that commands executed inside the container will always run as root. * Use numerical id for root rather than name --- scan/executil.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scan/executil.go b/scan/executil.go index 2835367e..976b780c 100644 --- a/scan/executil.go +++ b/scan/executil.go @@ -341,7 +341,7 @@ func decorateCmd(c conf.ServerInfo, cmd string, sudo bool) string { if c.IsContainer() { switch c.Containers.Type { case "", "docker": - cmd = fmt.Sprintf(`docker exec %s /bin/bash -c "%s"`, c.Container.ContainerID, cmd) + cmd = fmt.Sprintf(`docker exec --user 0 %s /bin/bash -c "%s"`, c.Container.ContainerID, cmd) case "lxd": cmd = fmt.Sprintf(`lxc exec %s -- /bin/bash -c "%s"`, c.Container.Name, cmd) }