Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
43 changes: 43 additions & 0 deletions 43 src/main/java/com/kpelykh/docker/client/DockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ public Version version() throws DockerException {
}
}
}


public int ping() throws DockerException {
WebResource webResource = client.resource(restEndpointUrl + "/_ping");

try {
LOGGER.trace("GET: {}", webResource);
ClientResponse resp = webResource.get(ClientResponse.class);
return resp.getStatus();
} catch (UniformInterfaceException exception) {
throw new DockerException(exception);
}
}


/**
Expand Down Expand Up @@ -280,6 +293,36 @@ private String name(String name) {
return name.contains("/") ? name : authConfig.getUsername();
}

/**
* Tag an image into a repository
*
* @param image the local image to tag (either a name or an id)
* @param repository the repository to tag in
* @param tag any tag for this image
* @param force (not documented)
* @return the HTTP status code (201 for success)
*/
public int tag(String image, String repository, String tag, boolean force) throws DockerException {
Preconditions.checkNotNull(image, "image was not specified");
Preconditions.checkNotNull(repository, "repository was not specified");
Preconditions.checkNotNull(tag, " tag was not provided");

MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("repo", repository);
params.add("tag", tag);
params.add("force", String.valueOf(force));

WebResource webResource = client.resource(restEndpointUrl + "/images/" + image + "/tag").queryParams(params);

try {
LOGGER.trace("POST: {}", webResource);
ClientResponse resp = webResource.post(ClientResponse.class);
return resp.getStatus();
} catch (UniformInterfaceException exception) {
throw new DockerException(exception);
}
}

/**
* Create an image by importing the given stream of a tar file.
*
Expand Down
12 changes: 12 additions & 0 deletions 12 src/test/java/com/kpelykh/docker/client/test/DockerClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.util.List;
import java.util.Random;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.hamcrest.Matcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -569,6 +571,16 @@ public void testRemoveImage() throws DockerException, InterruptedException {
assertThat(containers, matcher);
}

@Test
public void testTagImage() throws DockerException, InterruptedException {
String tag = String.valueOf(RandomUtils.nextInt(Integer.MAX_VALUE));

Integer result = dockerClient.tag("busybox:latest", "docker-java/busybox", tag, false);
assertThat(result, equalTo(Integer.valueOf(201)));

dockerClient.removeImage("docker-java/busybox:" + tag);
}

/*
*
* ################ ## MISC TESTS ## ################
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.