Skip to content

Commit 552b05d

Browse files
author
Marcus Linke
committed
Refactoring of DockerClientConfig to better match with docker CLI
configuration options
1 parent 1cf2a46 commit 552b05d

File tree

16 files changed

+414
-347
lines changed

16 files changed

+414
-347
lines changed

README.md

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,56 +85,62 @@ For code examples, please look at the [Wiki](https://github.com/docker-java/dock
8585

8686
There are a couple of configuration items, all of which have sensible defaults:
8787

88-
* `url` The Docker URL, e.g. `https://localhost:2376` or `unix:///var/run/docker.sock`
89-
* `version` The API version, e.g. `1.16`.
90-
* `username` Your registry username (required to push containers).
91-
* `password` Your registry password.
92-
* `email` Your registry email.
93-
* `serverAddress` Your registry's address.
94-
* `dockerCertPath` Path to the docker certs.
88+
* `DOCKER_HOST` The Docker Host URL, e.g. `tcp://localhost:2376` or `unix:///var/run/docker.sock`
89+
* `DOCKER_TLS_VERIFY` enable/disable TLS verification (switch between `http` and `https` protocol)
90+
* `DOCKER_CERT_PATH` Path to the certificates needed for TLS verification
91+
* `DOCKER_CONFIG` Path for additional docker configuration files (like `.dockercfg`)
92+
* `api.version` The API version, e.g. `1.21`.
93+
* `registry.url` Your registry's address.
94+
* `registry.username` Your registry username (required to push containers).
95+
* `registry.password` Your registry password.
96+
* `registry.email` Your registry email.
9597

9698
There are three ways to configure, in descending order of precedence:
9799

98100
#### Programmatic:
99101
In your application, e.g.
100102

101103
DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder()
102-
.withVersion("1.16")
103-
.withUri("https://my-docker-host.tld:2376")
104-
.withUsername("dockeruser")
105-
.withPassword("ilovedocker")
106-
.withEmail("dockeruser@github.com")
107-
.withServerAddress("https://index.docker.io/v1/")
108-
.withDockerCertPath("/home/user/.docker")
104+
.withDockerHost("tcp://my-docker-host.tld:2376")
105+
.withDockerTlsVerify("1")
106+
.withDockerCertPath("/home/user/.docker/certs")
107+
.withDockerConfig("/home/user/.docker")
108+
.withApiVersion("1.21")
109+
.withRegistryUrl("https://index.docker.io/v1/")
110+
.withRegistryUsername("dockeruser")
111+
.withRegistryPassword("ilovedocker")
112+
.withRegistryEmail("dockeruser@github.com")
109113
.build();
110114
DockerClient docker = DockerClientBuilder.getInstance(config).build();
111115

112116
#### Properties
113117

114-
docker.io.url=https://localhost:2376
115-
docker.io.version=1.16
116-
docker.io.username=dockeruser
117-
docker.io.password=ilovedocker
118-
docker.io.email=dockeruser@github.com
119-
docker.io.serverAddress=https://index.docker.io/v1/
120-
docker.io.dockerCertPath=/home/user/.docker
121-
118+
DOCKER_HOST=tcp://localhost:2376
119+
DOCKER_TLS_VERIFY=1
120+
DOCKER_CERT_PATH=/home/user/.docker/certs
121+
DOCKER_CONFIG=/home/user/.docker
122+
api.version=1.21
123+
registry.url=https://index.docker.io/v1/
124+
registry.username=dockeruser
125+
registry.password=ilovedocker
126+
registry.email=dockeruser@github.com
122127

123128
##### System Properties:
124129

125-
java -Ddocker.io.username=dockeruser pkg.Main
130+
java -Dregistry.username=dockeruser pkg.Main
126131

127132
##### System Environment
128133

129-
export DOCKER_URL=http://localhost:2376
130-
131-
Note: we also auto-detect defaults. If you use `DOCKER_HOST` we use that value, and if `DOCKER_CERT_PATH` or `DOCKER_TLS_VERIFY=1` is set, we switch to SSL.
134+
export DOCKER_URL=tcp://localhost:2376
135+
export DOCKER_TLS_VERIFY=1
136+
export DOCKER_CERT_PATH=/home/user/.docker/certs
137+
export DOCKER_CONFIG=/home/user/.docker
132138

133139
##### File System
134140

135-
In `$HOME/.docker.io.properties`
141+
In `$HOME/.docker-java.properties`
136142

137143
##### Class Path
138144

139-
In the class path at `/docker.io.properties`
145+
In the class path at `/docker-java.properties`
140146

src/main/java/com/github/dockerjava/api/command/DockerCmdExecFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.io.Closeable;
44
import java.io.IOException;
55

6+
import javax.net.ssl.SSLContext;
7+
68
import com.github.dockerjava.core.DockerClientConfig;
79

810
public interface DockerCmdExecFactory extends Closeable {
@@ -105,6 +107,8 @@ public interface DockerCmdExecFactory extends Closeable {
105107

106108
public DisconnectFromNetworkCmd.Exec createDisconnectFromNetworkCmdExec();
107109

110+
public DockerCmdExecFactory withSSLContext(SSLContext sslContext);
111+
108112
@Override
109113
public void close() throws IOException;
110114

0 commit comments

Comments
 (0)