Reputation: 5124
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?
Upvotes: 2
Views: 2005
Reputation: 633
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.
Upvotes: 0
Reputation: 4701
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();
Upvotes: 2