From 7c3a38d3793bea3999f4a55c3bdc0426bf52f7cb Mon Sep 17 00:00:00 2001 From: Karim Date: Fri, 5 Apr 2019 08:51:57 +0100 Subject: [PATCH] Support for docker images that set the USER directive. Changes the docker user to root for the init script to configure the network, then drops to the configured user (or root if one is not defined) for continuing booting the image. --- gns3server/compute/docker/docker_vm.py | 4 ++++ gns3server/compute/docker/resources/init.sh | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gns3server/compute/docker/docker_vm.py b/gns3server/compute/docker/docker_vm.py index ed5e0009..68d9c20f 100644 --- a/gns3server/compute/docker/docker_vm.py +++ b/gns3server/compute/docker/docker_vm.py @@ -311,6 +311,7 @@ class DockerVM(BaseNode): "Tty": True, "OpenStdin": True, "StdinOnce": False, + "User": "root", "HostConfig": { "CapAdd": ["ALL"], "Privileged": True, @@ -342,6 +343,9 @@ class DockerVM(BaseNode): # Give the information to the container the list of volume path mounted params["Env"].append("GNS3_VOLUMES={}".format(":".join(self._volumes))) + # Pass user configured for image to init script + params["Env"].append("GNS3_USER={}".format(image_infos.get("Config", {"User": ""})["User"])) + variables = self.project.variables if not variables: variables = [] diff --git a/gns3server/compute/docker/resources/init.sh b/gns3server/compute/docker/resources/init.sh index 54bbeefc..bc33ea1c 100755 --- a/gns3server/compute/docker/resources/init.sh +++ b/gns3server/compute/docker/resources/init.sh @@ -87,6 +87,9 @@ done ifup -a -f # continue normal docker startup -PATH="$OLD_PATH" -exec "$@" - +GNS3_CMD="PATH=$OLD_PATH exec" +while test "$#" -gt 0 ; do + GNS3_CMD="${GNS3_CMD} \"${1//\"/\\\"}\"" + shift +done +exec su ${GNS3_USER-root} -p -c "$GNS3_CMD"