diff --git a/api/handlers.go b/api/handlers.go index 6cd4e07fa2..68f2838bcc 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -552,6 +552,14 @@ func getEvents(c *context, w http.ResponseWriter, r *http.Request) { c.eventsHandler.Wait(r.RemoteAddr, until) } +// POST /exec/{execid:.*}/start +func postExecStart(c *context, w http.ResponseWriter, r *http.Request) { + if r.Header.Get("Connection") == "" { + proxyContainer(c, w, r) + } + proxyHijack(c, w, r) +} + // POST /containers/{name:.*}/exec func postContainersExec(c *context, w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] diff --git a/api/primary.go b/api/primary.go index e473922f31..cc7fd2669b 100644 --- a/api/primary.go +++ b/api/primary.go @@ -71,7 +71,7 @@ var routes = map[string]map[string]handler{ "/containers/{name:.*}/attach": proxyHijack, "/containers/{name:.*}/copy": proxyContainer, "/containers/{name:.*}/exec": postContainersExec, - "/exec/{execid:.*}/start": proxyHijack, + "/exec/{execid:.*}/start": postExecStart, "/exec/{execid:.*}/resize": proxyContainer, "/volumes": postVolumes, }, diff --git a/test/integration/api/exec.bats b/test/integration/api/exec.bats index 48539ebe9a..a83baf0866 100644 --- a/test/integration/api/exec.bats +++ b/test/integration/api/exec.bats @@ -12,7 +12,7 @@ function teardown() { swarm_manage docker_swarm create --name test_container busybox sleep 100 - # if container is not running, exec will failed + # if container is not running, exec will fail run docker_swarm exec test_container ls [ "$status" -ne 0 ] [[ "$output" == *"is not running"* ]] @@ -26,3 +26,22 @@ function teardown() { [ "$status" -eq 0 ] [ "$output" == "foobar" ] } + +@test "docker exec -d" { + start_docker_with_busybox 2 + swarm_manage + docker_swarm create --name test_container busybox sleep 100 + + # if container is not running, exec will fail + run docker_swarm exec -d test_container ls + [ "$status" -ne 0 ] + [[ "$output" == *"is not running"* ]] + + docker_swarm start test_container + + # make sure container is up and not paused + [ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ] + + run docker_swarm exec -d test_container echo foobar + [ "$status" -eq 0 ] +}