question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Start Container Constructs Incorrect POST

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
KostyaShacommented, Jul 4, 2016

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 😦

0reactions
KostyaShacommented, Aug 15, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix and Debug Docker Containers Like a Superhero
Confirm that permissions are incorrect. Run a chmod 774 command to let this file read, write, and execute for all users. Use docker...
Read more >
Builds in docker fail with 'Invalid argument' when doing RUN ...
When running buildah in GitLab CI (docker), using RUN after VOLUME fails since buildah 1.20.1. Dockerfile: FROM registry.fedoraproject.org/ ...
Read more >
9 Common Dockerfile Mistakes - Runnablog
This will ensure that your builds run as fast as possible. 4. Using :latest. Many Dockerfiles use the FROM node:latest pattern at the...
Read more >
Docker container not starting (docker start) - Stack Overflow
You are trying to run bash , an interactive shell that requires a tty in order to operate. It doesn't really make sense...
Read more >
Running a Docker container as a non-root user - Medium
Sometimes, when we run builds in Docker containers, the build creates files in a folder that's mounted into the container from the host...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found