X Tutup
Skip to content

Allow to send empty messages in StartContainerCmd#111

Merged
marcuslinke merged 2 commits intodocker-java:masterfrom
albers:empty-start-command
Dec 11, 2014
Merged

Allow to send empty messages in StartContainerCmd#111
marcuslinke merged 2 commits intodocker-java:masterfrom
albers:empty-start-command

Conversation

@albers
Copy link
Copy Markdown
Contributor

@albers albers commented Dec 11, 2014

There is something special about starting a container via POST /containers/(id)/start:
If the posted message body is not empty, any previous container customization will be reset to its defaults.

To illustrate, here are two variants of creating a container with custom DNS and then starting it.

# OK
$ id=$(docker create --dns 8.8.8.8 nginx)
$ curl -XPOST -H 'Content-type: application/json' http://localhost:2375/containers/$id/start -d '{}'
$ docker inspect -f '{{ .HostConfig.Dns }} {{ .State.Running }}' $id
[8.8.8.8] true

# DNS setting gets lost by setting Privileged.
$ id=$(docker create --dns 8.8.8.8 nginx)
$ curl -XPOST -H 'Content-type: application/json' http://localhost:2375/containers/$id/start -d '{"Privileged":false}'
$ docker inspect -f '{{ .HostConfig.Dns }} {{ .State.Running }}' $id
<no value> true

Because docker-java currently includes lots of parameters in its StartContainerCmdImpl, there is no way to just start a preconfigured container, see the newly added StartContainerCmdImplTest.existingHostConfigIsPreservedByBlankStartCmd() that fails with the current implementation.

This PR solves the issue by introducing a notion of undefinedness for all parameters and ignoring all empty parameters when serializing.

Thus, dockerClient.startContainerCmd(container.getId()).exec() will send {} as message body.

This illustrates an issue with current docker-java: you cannot send a
StartContainerCmd without payload.
Any payload sent with the StartContainerCmd will cause the target
container to lose its customization.
So in order to just start a preconfigured container you must be able to
send an empty "{}" message to the /containers/{id}/start endpoint.

This is accomplished by all configuration defaulting to null in
combination with @JsonInclude(NON_EMPTY).
marcuslinke added a commit that referenced this pull request Dec 11, 2014
Allow to send empty messages in StartContainerCmd
@marcuslinke marcuslinke merged commit 308b1b7 into docker-java:master Dec 11, 2014
@marcuslinke
Copy link
Copy Markdown
Contributor

@albers Thanks! Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup