Skip to content

Commit

Permalink
Config to specify isolation technology for container
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Kulkarni <Rahul.Kulkarni@microfocus.com>
  • Loading branch information
Rahul Kulkarni authored and rohanKanojia committed Mar 12, 2021
1 parent 3d9cdbf commit b0668e4
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
- `assembly.inline` is removed when external properties are enabled ([1082](https://github.com/fabric8io/docker-maven-plugin/issues/1082))
- Fix Support for Podman REST API(when configured) Related to ([1330](https://github.com/fabric8io/docker-maven-plugin/issues/1330))
- Fix ignored `SHELL` directive when provided in XML configuration (#1418)
- Restore support for getting a random container name ([1352](https://github.com/fabric8io/docker-maven-plugin/issues/1352))
- Provide exception messages that occurred during stop ([1435](https://github.com/fabric8io/docker-maven-plugin/pull/1435))
- Make Maven build Reproducible ([1406](https://github.com/fabric8io/docker-maven-plugin/pull/1406))
- Fix Windows tests ([1416](https://github.com/fabric8io/docker-maven-plugin/pull/1417))
- Add a skipPom parameter, skipping a project if packaging is pom ([1388](https://github.com/fabric8io/docker-maven-plugin/pull/1388))
- Add support for config to specify isolation technology for container ([1376](https://github.com/fabric8io/docker-maven-plugin/pull/1376))
- Add Docker build cache friendly example utilizing Spring Boot Layered JAR and Maven Assembly Plugin ([1412](https://github.com/fabric8io/docker-maven-plugin/pull/1412))

* **0.34.1** (2020-09-27)
- Fix NPE with "skipPush" and no build configuration given ([#1381](https://github.com/fabric8io/docker-maven-plugin/issues/1381))
Expand Down
5 changes: 5 additions & 0 deletions src/main/asciidoc/inc/_docker-start.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ include::start/_wait.adoc[]
=== Logging

include::start/_logging.adoc[]

[[start-isolation]]
=== Isolation

include::start/_isolation.adoc[]
3 changes: 3 additions & 0 deletions src/main/asciidoc/inc/start/_configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ The `<run>` configuration element knows the following sub elements:
| <<start-logging, *log*>>
| Log configuration for whether and how log messages from the running containers should be printed. This also can configure the https://docs.docker.com/engine/admin/logging/overview[log driver] to use. See <<start-logging,Logging>> for a detailed description.

| <<start-isolation, *isolation*>>
| This option sets container's isolation technology. See <<start-isolation,Isolation>> for a detailed description.

| *memory*
| Memory limit in bytes.

Expand Down
30 changes: 30 additions & 0 deletions src/main/asciidoc/inc/start/_isolation.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
==== Specify isolation technology for container

The following configuration option under <run> session is equivalent of `--isolation <value>` when running a docker container

.Example
[source,xml]
<run>
<isolation>hyperv</isolation>
</run>

This option is useful in situations where you are running Docker containers on Windows. The --isolation <value> option sets a container's isolation technology. On Linux, the only supported is the default option which uses Linux namespaces.

.On Windows, isolation can take one of these values:
[cols="1,5"]
|===
|Value |Description

|default
|Use the value specified by the Docker daemon's --exec-opt or system default (see below).

|process
|Shared-kernel namespace isolation (not supported on Windows client operating systems older than Windows 10 1809).

|hyperv
|Hyper-V hypervisor partition-based isolation.
|===

The default isolation on Windows server operating systems is process. The default isolation on Windows client operating systems is hyperv. An attempt to start a container on a client operating system older than Windows 10 1809 with --isolation process will fail.

See https://docs.docker.com/engine/reference/commandline/run/#specify-isolation-technology-for-container---isolation[isolation technology for container] for a detailed description.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public ContainerHostConfig dnsSearch(List<String> dnsSearch) {
return addAsArray("DnsSearch", dnsSearch);
}

public ContainerHostConfig isolation(String isolation) { return add("Isolation",isolation); }

public ContainerHostConfig cpuShares(Long cpuShares) {
return add("CpuShares", cpuShares);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public boolean isDefault() {
@Parameter
private List<String> extraHosts;

@Parameter
private String isolation;

@Parameter
private Long cpuShares;

Expand Down Expand Up @@ -256,6 +259,8 @@ public Long getMemorySwap() {
return memorySwap;
}

public String getIsolation() { return isolation; }

public Long getCpuShares() {
return cpuShares;
}
Expand Down Expand Up @@ -591,6 +596,11 @@ public Builder log(LogConfiguration log) {
return this;
}

public Builder isolation (String isolation) {
config.isolation = isolation;
return this;
}

public Builder cpuShares(Long cpuShares){
config.cpuShares = cpuShares;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ private RunImageConfiguration createRunConfiguration(DockerComposeServiceWrapper
// stop_signal not supported
.ulimits(wrapper.getUlimits())
.volumes(wrapper.getVolumeConfig())
.isolation(wrapper.getIsolation())
.cpuShares(wrapper.getCpuShares())
.cpus(wrapper.getCpusCount())
.cpuSet(wrapper.getCpuSet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ public String getCpuSet() {
return asString("cpuset");
}

public String getIsolation() {return asString("isolation"); }

public Long getCpuShares() {
return asLong("cpu_shares");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum ConfigKey {
CLEANUP,
CPUS,
CPUSET,
ISOLATION,
CPUSHARES,
CACHE_FROM,
CMD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ private RunImageConfiguration extractRunConfiguration(ImageConfiguration fromCon
.imagePullPolicy(valueProvider.getString(IMAGE_PULL_POLICY_RUN, config == null ? null : config.getImagePullPolicy()))
.ulimits(extractUlimits(config == null ? null : config.getUlimits(), valueProvider))
.tmpfs(valueProvider.getList(TMPFS, config == null ? null : config.getTmpfs()))
.isolation(valueProvider.getString(ISOLATION, config == null ? null : config.getIsolation()))
.cpuShares(valueProvider.getLong(CPUSHARES, config == null ? null : config.getCpuShares()))
.cpus(valueProvider.getLong(CPUS, config == null ? null : config.getCpus()))
.cpuSet(valueProvider.getString(CPUSET, config == null ? null : config.getCpuSet()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ ContainerHostConfig createContainerHostConfig(RunImageConfiguration runConfig, P
.logConfig(runConfig.getLogConfiguration())
.tmpfs(runConfig.getTmpfs())
.ulimits(runConfig.getUlimits())
.isolation(runConfig.getIsolation())
.cpuShares(runConfig.getCpuShares())
.cpus(runConfig.getCpus())
.cpuSet(runConfig.getCpuSet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected void validateRunConfiguration(RunImageConfiguration runConfig) {
assertEquals((Long) 1L, runConfig.getMemory());
assertEquals((Long) 1L, runConfig.getMemorySwap());
assertEquals((Long) 1000000000L, runConfig.getCpus());
assertEquals("default", runConfig.getIsolation());
assertEquals((Long) 1L, runConfig.getCpuShares());
assertEquals("0,1", runConfig.getCpuSet());
assertEquals(getEnvPropertyFile(),runConfig.getEnvPropertyFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ void validateRunConfiguration(RunImageConfiguration runConfig) {
assertEquals((Long) 1L, runConfig.getMemorySwap());
assertEquals("0,1", runConfig.getCpuSet());
assertEquals((Long)1000000000L, runConfig.getCpus());
assertEquals("default", runConfig.getIsolation());
assertEquals((Long) 1L, runConfig.getCpuShares());
assertEquals(null,runConfig.getEnvPropertyFile());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ protected void validateRunConfiguration(RunImageConfiguration runConfig) {
assertEquals((Long) 1L, runConfig.getMemory());
assertEquals((Long) 1L, runConfig.getMemorySwap());
assertEquals((Long) 1000000000L, runConfig.getCpus());
assertEquals("default",runConfig.getIsolation());
assertEquals((Long) 1L, runConfig.getCpuShares());
assertEquals("0,1", runConfig.getCpuSet());
assertEquals("/tmp/envProps.txt",runConfig.getEnvPropertyFile());
Expand Down Expand Up @@ -1108,6 +1109,7 @@ private String[] getTestData() {
k(ConfigKey.SECURITY_OPTS) + ".1", "seccomp=unconfined",
k(ConfigKey.CPUS), "1000000000",
k(ConfigKey.CPUSET), "0,1",
k(ConfigKey.ISOLATION),"default",
k(ConfigKey.CPUSHARES), "1",
k(ConfigKey.CMD), "command.sh",
k(ConfigKey.DNS) + ".1", "8.8.8.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ private void givenARunConfiguration() {
.memorySwap(1L)
.cpus(1000000000L)
.cpuSet("0,1")
.isolation("default")
.cpuShares(1L)
.env(env())
.cmd("date")
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- CAP
command: command.sh
cgroup_parent: cgroup_parent
isolation: default
cpu_shares: 1
cpuset: 0,1
cpus: 1
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/docker/containerCreateConfigAll.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"Soft":2048
}
],
"Isolation": "default",
"CpuShares":1,
"NanoCpus": 1000000000,
"CpusetCpus":"0,1",
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/docker/containerHostConfigAll.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"Soft":2048
}
],
"Isolation": "default",
"CpuShares":1,
"NanoCpus":1000000000,
"CpusetCpus":"0,1",
Expand Down

0 comments on commit b0668e4

Please sign in to comment.