Start Container Constructs Incorrect POST
See original GitHub issueIn 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
.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:14 (13 by maintainers)
Top GitHub Comments
Hm… i have PR with updated jersey and deps in #620 but it started failing with connection pool. I think our problem now that we IT doesn’t pass on travis 😦
Fixed start to not send body, related only to jersey as netty decodes body in different way. If it will repeat for some calls, will require more proper fix.