From a3986cac05207bdcc62a66b1b5c8a19c092d7f7b Mon Sep 17 00:00:00 2001 From: xianlubird Date: Thu, 21 Apr 2016 13:35:59 +0800 Subject: [PATCH] Fix the bug that start container mess the host config Signed-off-by: Xianlu --- api/handlers.go | 2 +- test/integration/api/start.bats | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/api/handlers.go b/api/handlers.go index bb7155cb85..f2122dbfb2 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -797,7 +797,7 @@ func postContainersStart(c *context, w http.ResponseWriter, r *http.Request) { } r.Body.Close() - if len(buf) <= 2 { + if len(buf) <= 2 || (len(buf) == 4 && string(buf) == "null") { hostConfig = nil } else { if err := json.Unmarshal(buf, hostConfig); err != nil { diff --git a/test/integration/api/start.bats b/test/integration/api/start.bats index 859065542a..2a1ac968a8 100644 --- a/test/integration/api/start.bats +++ b/test/integration/api/start.bats @@ -47,4 +47,28 @@ function teardown() { # Inspect HostConfig of container, should have PublishAllPorts set to true run docker_swarm inspect test_container [[ "${output}" == *'"PublishAllPorts": true'* ]] -} \ No newline at end of file +} + +@test "docker start with null hostConfig" { + start_docker_with_busybox 2 + swarm_manage + + # create with PublishAllPorts true + docker_swarm create --name test_container -P busybox sleep 1000 + + # make sure created container exists + # new created container has no status + run docker_swarm ps -l + [ "${#lines[@]}" -eq 2 ] + [[ "${lines[1]}" == *"test_container"* ]] + + # start with null hostConfig + curl -s -H "Content-Type: application/json" -X POST -d 'null' ${SWARM_HOSTS[0]}/v1.23/containers/test_container/start + + # Verify + [ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ] + + # Inspect HostConfig of container, should have PublishAllPorts set to true + run docker_swarm inspect test_container + [[ "${output}" == *'"PublishAllPorts": true'* ]] +}