|
10 | 10 | import com.github.dockerjava.api.command.InspectContainerResponse; |
11 | 11 | import com.github.dockerjava.api.exception.ConflictException; |
12 | 12 | import com.github.dockerjava.api.exception.DockerException; |
| 13 | +import com.github.dockerjava.api.DockerClient; |
| 14 | +import com.github.dockerjava.core.DefaultDockerClientConfig; |
13 | 15 | import com.github.dockerjava.api.exception.InternalServerErrorException; |
14 | 16 | import com.github.dockerjava.api.exception.NotFoundException; |
15 | 17 | import com.github.dockerjava.api.model.AuthConfig; |
|
58 | 60 | import static com.github.dockerjava.api.model.HostConfig.newHostConfig; |
59 | 61 | import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_23; |
60 | 62 | import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_24; |
| 63 | +import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_43; |
61 | 64 | import static com.github.dockerjava.junit.DockerMatchers.isGreaterOrEqual; |
62 | 65 | import static com.github.dockerjava.junit.DockerMatchers.mountedVolumes; |
63 | 66 | import static com.github.dockerjava.core.DockerRule.DEFAULT_IMAGE; |
@@ -1141,4 +1144,33 @@ public void shouldHandleANetworkAliasWithoutACustomNetworkGracefully() { |
1141 | 1144 | .withCmd("sleep", "9999") |
1142 | 1145 | .exec(); |
1143 | 1146 | } |
| 1147 | + |
| 1148 | + @Test |
| 1149 | + public void createContainerWithAnnotations() throws DockerException { |
| 1150 | + DefaultDockerClientConfig forcedConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() |
| 1151 | + .withApiVersion(VERSION_1_43) |
| 1152 | + .withRegistryUrl("https://index.docker.io/v1/") |
| 1153 | + .build(); |
| 1154 | + |
| 1155 | + DockerClient forcedClient = CmdIT.createDockerClient(forcedConfig); |
| 1156 | + Map<String, String> annotations = new HashMap<>(); |
| 1157 | + annotations.put("com.example.key1", "value1"); |
| 1158 | + annotations.put("com.example.key2", "value2"); |
| 1159 | + |
| 1160 | + CreateContainerResponse container = forcedClient.createContainerCmd(DEFAULT_IMAGE) |
| 1161 | + .withCmd("sleep", "9999") |
| 1162 | + .withHostConfig(newHostConfig() |
| 1163 | + .withAnnotations(annotations)) |
| 1164 | + .exec(); |
| 1165 | + |
| 1166 | + LOG.info("Created container {}", container.toString()); |
| 1167 | + |
| 1168 | + assertThat(container.getId(), not(is(emptyString()))); |
| 1169 | + |
| 1170 | + InspectContainerResponse inspectContainerResponse = forcedClient.inspectContainerCmd(container.getId()).exec(); |
| 1171 | + |
| 1172 | + assertThat(inspectContainerResponse.getHostConfig().getAnnotations(), equalTo(annotations)); |
| 1173 | + assertThat(inspectContainerResponse.getHostConfig().getAnnotations().get("com.example.key1"), equalTo("value1")); |
| 1174 | + assertThat(inspectContainerResponse.getHostConfig().getAnnotations().get("com.example.key2"), equalTo("value2")); |
| 1175 | + } |
1144 | 1176 | } |
0 commit comments