From 8935d434c58d3ea3b3d86fa01e8b4be7d2d05858 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 1 Aug 2017 08:53:56 +0100 Subject: [PATCH 1/2] run a normal (rather than login) shell in containers That way PATH is preserved. Fixes #2550. --- probe/docker/controls.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/probe/docker/controls.go b/probe/docker/controls.go index 88b775e61..f2eb51e6e 100644 --- a/probe/docker/controls.go +++ b/probe/docker/controls.go @@ -112,7 +112,7 @@ func (r *registry) execContainer(containerID string, req xfer.Request) xfer.Resp AttachStdout: true, AttachStderr: true, Tty: true, - Cmd: []string{"/bin/sh", "-l", "-c", "TERM=xterm exec $( (type getent > /dev/null 2>&1 && getent passwd root | cut -d: -f7 2>/dev/null) || echo /bin/sh)"}, + Cmd: []string{"/bin/sh", "-c", "TERM=xterm exec $( (type getent > /dev/null 2>&1 && getent passwd root | cut -d: -f7 2>/dev/null) || echo /bin/sh)"}, Container: containerID, }) if err != nil { From 994719b81587043e52b571cdc8d07bd546dfc478 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 1 Aug 2017 09:04:45 +0100 Subject: [PATCH 2/2] test PATH propagation in container shells --- integration/410_container_control_test.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/integration/410_container_control_test.sh b/integration/410_container_control_test.sh index 5c2f50289..abe74c541 100755 --- a/integration/410_container_control_test.sh +++ b/integration/410_container_control_test.sh @@ -8,16 +8,19 @@ start_suite "Test container controls" weave_on "$HOST1" launch scope_on "$HOST1" launch -CID=$(weave_proxy_on "$HOST1" run -dti --name alpine alpine /bin/sh) +CID=$(weave_proxy_on "$HOST1" run -dti --name alpine -e PATH=/home:/usr/bin alpine /bin/sh) wait_for_containers "$HOST1" 60 alpine assert "docker_on $HOST1 inspect --format='{{.State.Running}}' alpine" "true" PROBEID=$(docker_on "$HOST1" logs weavescope 2>&1 | grep "probe starting" | sed -n 's/^.*ID \([0-9a-f]*\)$/\1/p') -# Execute 'echo foo' in a container tty and check its output +# Execute 'echo $PATH' in a container tty and check its output - as +# well as checking basic operation, this also checks that the +# container's PATH settings are respected, which isn't the case for +# login shells. PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$CID;/docker_exec_container" | jq -r '.pipe') -assert "(sleep 1 && echo 'echo foo' && sleep 1) | wscat -b 'ws://$HOST1:4040/api/pipe/$PIPEID' | col -pb" "alpine:/# 6necho foo\nfoo\nalpine:/# 6n" +assert "(sleep 1 && echo 'echo \$PATH' && sleep 1) | wscat -b 'ws://$HOST1:4040/api/pipe/$PIPEID' | col -pb" "/ # 6necho \$PATH\n/home:/usr/bin\n/ # 6n" assert_raises "curl -f -X POST 'http://$HOST1:4040/api/control/$PROBEID/$CID;/docker_stop_container'"