In docker-java-3.0.0, the StartContainerCmdExec class sends a POST to the Docker API with garbage in the request body, resulting in an HTTP 400 or HTTP 500 (depending on the version of Docker.)
This Scala program reproduces the error reliably (against Docker 1.12):
package com.github.m4dc4p.dockerjava
object Main extends App {
import com.github.dockerjava.core._
import com.github.dockerjava.api._
val docker: DockerClient = DockerClientBuilder.getInstance(
DockerClientConfig.createDefaultConfigBuilder()
// .withDockerHost("tcp://127.0.0.1:2375") // uncomment for windows
.withApiVersion("1.21")
.build())
.build()
val container = docker.createContainerCmd("mysql/mysql-server:latest")
.withEnv("MYSQL_ALLOW_EMPTY_PASSWORD=yes")
.exec()
docker.startContainerCmd(container.getId).exec() // HTTP 500/HTTP 400
}
Here is a trace of the relevant output. I marked the garbage in the body of the POST request with ***:
764 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "POST /v1.21/containers/34e03000dab1be0bc41cd5acd55dae34aa2eb3b743c5c92b3a9c150209a42452/start HTTP/1.1[\r][\n]"
764 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: application/json[\r][\n]"
764 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/json[\r][\n]"
764 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Jersey/2.11 (Apache HttpClient 4.3.1)[\r][\n]"
764 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Transfer-Encoding: chunked[\r][\n]"
764 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: 127.0.0.1:2375[\r][\n]"
764 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
764 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
764 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
***765 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "2[\r][\n]"
***765 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "{}[\r][\n]"
***765 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "0[\r][\n]"
765 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
768 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 500 Internal Server Error[\r][\n]"
768 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length: 4[\r][\n]"
768 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: text/plain; charset=utf-8[\r][\n]"
768 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Tue, 21 Jun 2016 10:27:16 GMT[\r][\n]"
768 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: Docker/1.12.0-rc2 (linux)[\r][\n]"
768 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"
768 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
768 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 500 Internal Server Error
Note that removing the API version results in an HTTP 400.
The .../start endpoint supports a (deprecated) HostConfig JSON blob in the body, and docker-java must have supported that at some point. However, the StartContainerCmd interface does not allow you to add such a thing to the request, but StartContainerCmdExec contains some vestige of the old behavior and tries to add a JSON blob to the post body. The fix is simple - pass null to the post request in com.github.dockerjava.jaxrs.StartContainerCmdExec#execute.
In docker-java-3.0.0, the StartContainerCmdExec class sends a POST to the Docker API with garbage in the request body, resulting in an HTTP 400 or HTTP 500 (depending on the version of Docker.)
This Scala program reproduces the error reliably (against Docker 1.12):
Here is a trace of the relevant output. I marked the garbage in the body of the POST request with
***:Note that removing the API version results in an HTTP 400.
The
.../startendpoint supports a (deprecated) HostConfig JSON blob in the body, and docker-java must have supported that at some point. However, theStartContainerCmdinterface does not allow you to add such a thing to the request, butStartContainerCmdExeccontains some vestige of the old behavior and tries to add a JSON blob to the post body. The fix is simple - passnullto thepostrequest incom.github.dockerjava.jaxrs.StartContainerCmdExec#execute.