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
This commit is contained in:
Paul Furtado
2017-03-31 05:58:00 -04:00
committed by Teppei Fukuda
parent bdf6efeaac
commit d4bec0dd9a

View File

@@ -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)
}