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?

2 Answers 2

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();

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.