Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/main/java/com/kpelykh/docker/client/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@ static Config createConfig() throws DockerException {
throw new DockerException(e);
}

for (String s : new String[]{"url", "version", "username", "password", "email"}) {
final String key = "docker.io." + s;
if (System.getProperties().keySet().contains(key)) {
p.setProperty(key, System.getProperty(key));
}
}
final File file = new File(System.getProperty("user.home"), ".docker.io.properties");

final File file = new File(System.getProperty("user.name"), ".docker.io.properties");
System.out.println(file);
if (file.isFile()) {
if (file.isFile()) {
try {
final FileInputStream in = new FileInputStream(file);
try {
Expand All @@ -44,6 +37,13 @@ static Config createConfig() throws DockerException {
}
}

for (String s : new String[]{"url", "version", "username", "password", "email"}) {
final String key = "docker.io." + s;
if (System.getProperties().keySet().contains(key)) {
p.setProperty(key, System.getProperty(key));
}
}

final Config c = new Config();

c.url = URI.create(p.getProperty("docker.io.url"));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kpelykh/docker/client/DockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void setCredentials(String username, String password, String email) {
}
authConfig = new AuthConfig();
authConfig.setUsername(username);
authConfig.setPassword(password);
authConfig.setPassword(password);
authConfig.setEmail(email);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ContainerInspectResponse {
private ContainerState state;

@JsonProperty("Image")
private String image;
private String imageId;

@JsonProperty("NetworkSettings")
private NetworkSettings networkSettings;
Expand Down Expand Up @@ -119,12 +119,12 @@ public void setState(ContainerState state) {
this.state = state;
}

public String getImage() {
return image;
public String getImageId() {
return imageId;
}

public void setImage(String image) {
this.image = image;
public void setImageId(String image) {
this.imageId = image;
}

public NetworkSettings getNetworkSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ImageInspectResponse {

@JsonProperty("container_config") private ContainerConfig containerConfig;

@JsonProperty("Size") private int size;
@JsonProperty("Size") private long size;

@JsonProperty("docker_version") private String dockerVersion;

Expand Down Expand Up @@ -76,11 +76,11 @@ public void setContainerConfig(ContainerConfig containerConfig) {
this.containerConfig = containerConfig;
}

public int getSize() {
public long getSize() {
return size;
}

public void setSize(int size) {
public void setSize(long size) {
this.size = size;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public void beforeTest() throws DockerException {
LOG.info("Connecting to Docker server at " + url);
dockerClient = new DockerClient(url);

LOG.info("Creating image 'busybox'");
LOG.info("Pulling image 'busybox'");
// need to block until image is pulled completely
logResponseStream(dockerClient.pull("busybox"));



assertNotNull(dockerClient);
LOG.info("======================= END OF BEFORETEST =======================\n\n");
Expand Down
30 changes: 25 additions & 5 deletions src/test/java/com/kpelykh/docker/client/test/DockerClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,45 @@ public void testImages() throws DockerException {

@Test
public void testListContainers() throws DockerException {

String testImage = "hackmann/empty";

LOG.info("Pulling image 'hackmann/empty'");
// need to block until image is pulled completely
logResponseStream(dockerClient.pull(testImage));
tmpImgs.add(testImage);

List<Container> containers = dockerClient.listContainers(true);
assertThat(containers, notNullValue());
LOG.info("Container List: {}", containers);

int size = containers.size();

ContainerConfig containerConfig = new ContainerConfig();
containerConfig.setImage("busybox");
containerConfig.setImage(testImage);
containerConfig.setCmd(new String[] { "echo" });

ContainerCreateResponse container1 = dockerClient
.createContainer(containerConfig);

assertThat(container1.getId(), not(isEmptyString()));

ContainerInspectResponse containerInspectResponse = dockerClient.inspectContainer(container1.getId());

assertThat(containerInspectResponse.getConfig().getImage(), is(equalTo(testImage)));


dockerClient.startContainer(container1.getId());
tmpContainers.add(container1.getId());

LOG.info("container id: " + container1.getId());

List containers2 = dockerClient.listContainers(true);
List<Container> containers2 = dockerClient.listContainers(true);

for(Container container: containers2) {
LOG.info("listContainer: id=" + container.getId() +" image=" + container.getImage());
}

assertThat(size + 1, is(equalTo(containers2.size())));
Matcher matcher = hasItem(hasField("id", startsWith(container1.getId())));
assertThat(containers2, matcher);
Expand All @@ -179,12 +199,12 @@ public void testListContainers() throws DockerException {
assertThat(filteredContainers.size(), is(equalTo(1)));

for(Container container: filteredContainers) {
LOG.info("container: " + container);
LOG.info("filteredContainer: " + container.getImage());
}

Container container2 = filteredContainers.get(0);
assertThat(container2.getCommand(), not(isEmptyString()));
assertThat(container2.getImage(), equalTo("busybox:latest"));
assertThat(container2.getImage(), equalTo(testImage + ":latest"));
}

/*
Expand Down Expand Up @@ -232,7 +252,7 @@ public void testStartContainer() throws DockerException {
assertThat(containerInspectResponse.getId(),
startsWith(container.getId()));

assertThat(containerInspectResponse.getImage(), not(isEmptyString()));
assertThat(containerInspectResponse.getImageId(), not(isEmptyString()));
assertThat(containerInspectResponse.getState(), is(notNullValue()));

assertThat(containerInspectResponse.getState().running, is(true));
Expand Down