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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.Link;
import com.github.dockerjava.api.model.LogConfig;
import com.github.dockerjava.api.model.LxcConf;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Ports;
Expand Down Expand Up @@ -88,6 +89,8 @@ public static interface Exec extends DockerCmdSyncExec<CreateContainerCmd, Creat
public Link[] getLinks();

public LxcConf[] getLxcConf();

public LogConfig getLogConfig();

public String getMacAddress();

Expand Down Expand Up @@ -224,6 +227,8 @@ public static interface Exec extends DockerCmdSyncExec<CreateContainerCmd, Creat

public CreateContainerCmd withLxcConf(LxcConf... lxcConf);

public CreateContainerCmd withLogConfig(LogConfig logConfig);

public CreateContainerCmd withMemoryLimit(long memoryLimit);

public CreateContainerCmd withMemorySwap(long memorySwap);
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/github/dockerjava/api/model/HostConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class HostConfig {

@JsonProperty("LxcConf")
private LxcConf[] lxcConf;

@JsonProperty("LogConfig")
private LogConfig logConfig;

@JsonProperty("PortBindings")
private Ports portBindings;
Expand Down Expand Up @@ -66,13 +69,14 @@ public class HostConfig {
public HostConfig() {
}

public HostConfig(Bind[] binds, Link[] links, LxcConf[] lxcConf, Ports portBindings, boolean publishAllPorts,
public HostConfig(Bind[] binds, Link[] links, LxcConf[] lxcConf, LogConfig logConfig, Ports portBindings, boolean publishAllPorts,
boolean privileged, boolean readonlyRootfs, String[] dns, String[] dnsSearch, VolumesFrom[] volumesFrom,
String containerIDFile, Capability[] capAdd, Capability[] capDrop, RestartPolicy restartPolicy,
String networkMode, Device[] devices, String[] extraHosts, Ulimit[] ulimits) {
this.binds = new Binds(binds);
this.links = new Links(links);
this.lxcConf = lxcConf;
this.logConfig = logConfig;
this.portBindings = portBindings;
this.publishAllPorts = publishAllPorts;
this.privileged = privileged;
Expand All @@ -98,6 +102,11 @@ public Bind[] getBinds() {
public LxcConf[] getLxcConf() {
return lxcConf;
}

@JsonIgnore
public LogConfig getLogConfig() {
return (logConfig == null) ? new LogConfig() : logConfig;
}

public Ports getPortBindings() {
return portBindings;
Expand Down Expand Up @@ -177,6 +186,11 @@ public void setLinks(Link... links) {
public void setLxcConf(LxcConf[] lxcConf) {
this.lxcConf = lxcConf;
}

@JsonIgnore
public void setLogConfig(LogConfig logConfig) {
this.logConfig = logConfig;
}

public void setPortBindings(Ports portBindings) {
this.portBindings = portBindings;
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/com/github/dockerjava/api/model/LogConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.github.dockerjava.api.model;

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Log driver to use for a created/running container. The
* available types are:
*
* json-file (default)
* syslog
* journald
* none
*
* If a driver is specified that is NOT supported,docker
* will default to null. If configs are supplied that are
* not supported by the type docker will ignore them. In most
* cases setting the config option to null will suffice. Consult
* the docker remote API for a more detailed and up-to-date
* explanation of the available types and their options.
*/
public class LogConfig {

@JsonProperty("Type")
public String type;

@JsonProperty("Config")
public Map<String, String> config;

public LogConfig(String type, Map<String, String> config) {
this.type = type;
this.config = config;
}

public LogConfig() {
}

public String getType() {
return type;
}

public LogConfig setType(String type) {
this.type = type;
return this;
}

@JsonIgnore
public Map<String, String> getConfig() {
return config;
}

@JsonIgnore
public LogConfig setConfig(Map<String, String> config) {
this.config = config;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.github.dockerjava.api.model.ExposedPorts;
import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.Link;
import com.github.dockerjava.api.model.LogConfig;
import com.github.dockerjava.api.model.LxcConf;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Ports;
Expand Down Expand Up @@ -269,6 +270,12 @@ public Map<String, String> getLabels() {
public LxcConf[] getLxcConf() {
return hostConfig.getLxcConf();
}

@Override
@JsonIgnore
public LogConfig getLogConfig() {
return hostConfig.getLogConfig();
}

public String getMacAddress() {
return macAddress;
Expand Down Expand Up @@ -558,6 +565,13 @@ public CreateContainerCmd withLxcConf(LxcConf... lxcConf) {
this.hostConfig.setLxcConf(lxcConf);
return this;
}

@Override
public CreateContainerCmd withLogConfig(LogConfig logConfig) {
checkNotNull(logConfig, "logConfig was not specified");
this.hostConfig.setLogConfig(logConfig);
return this;
}

@Override
public CreateContainerCmdImpl withMacAddress(String macAddress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.Link;
import com.github.dockerjava.api.model.LogConfig;
import com.github.dockerjava.api.model.Ports;
import com.github.dockerjava.api.model.RestartPolicy;
import com.github.dockerjava.api.model.Ulimit;
Expand Down Expand Up @@ -534,4 +535,21 @@ public void createContainerWithLabels() throws DockerException {
labels.put("com.github.dockerjava.null", "");
assertThat(inspectContainerResponse.getConfig().getLabels(), is(equalTo(labels)));
}

@Test(groups = "ignoreInCircleCi")
public void createContainerWithLogConfig() throws DockerException {

LogConfig logConfig = new LogConfig("none", null);
CreateContainerResponse container = dockerClient.createContainerCmd("busybox").
withLogConfig(logConfig).exec();

LOG.info("Created container {}", container.toString());

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

InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();

// null becomes empty string
assertEquals(inspectContainerResponse.getHostConfig().getLogConfig().type, logConfig.type);
}
}