2

I'm trying to start a docker container using docker-java. Using the method DockerClient.startContainerCmd works for me, but I need to start the container with arguments. The StartContainerCmd class that is returned from this method does not have any methods to supply arguments before I execute it.

Is there a way to do it?

Idov
  • 5,006
  • 17
  • 69
  • 106

2 Answers2

2

The StartContainerCmd delegates to StartContainerCmdExec which abstracts the Start Container REST operation. The Operation has only one path parameter (id of the container). If you need to supply additional arguments you need to create the container with those arguments:

CreateContainerResponse container = dockerClient.createContainerCmd(IMAGE_NAME)
                .withCmd("cmd", "arg1", "arg2").exec()

get the id of the container and then start it:

dockerClient.startContainerCmd(container.getId()).exec();

b0gusb
  • 4,283
  • 2
  • 14
  • 33
0

It should work easily with https://www.github.com/amihaiemil/docker-java-api:

final Docker docker = new LocalDocker(...);//or RemoteDocker(...)
final Container container = docker.containers().create(/*JsonObject*/).start();

The JsonObject passed to Containers.create(...) should be the one that Docker's API expects as input (see API docs). In that JsonObject, you should also be able to specify startup scripts.

amihaiemil
  • 623
  • 8
  • 19