Skip to content

Commit

Permalink
Merge pull request #67 from whitem4rk/bugfix/#66
Browse files Browse the repository at this point in the history
[Bugfix/#66] Connect container with network
  • Loading branch information
whitem4rk authored Nov 6, 2024
2 parents 9f1a2cb + 8adc65e commit 463c2ed
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void customNetworkValidationCheck(List<CustomNetwork> customNetworkList)
for (CustomNetwork customNetwork : customNetworkList) {
for (CustomConfig config : customNetwork.getCustomIpam().getCustomConfig()) {
if (customNetwork.getName().equals(DEFAULT_BRIDGE_NETWORK_NAME)
&& config.getSubnet().equals(DEFAULT_BRIDGE_NETWORK_SUBNET)) {
&& !config.getSubnet().equals(DEFAULT_BRIDGE_NETWORK_SUBNET)) {
throw new CustomException(ErrorCode.NETWORK_CREATION_FAILED);
}
}
Expand Down Expand Up @@ -222,15 +222,25 @@ private List<Map<String, Object>> syncContainers(DockerClient dockerClient, List
.withBinds(binds)
.withMounts(mounts);

ContainerNetwork containerNetwork = new ContainerNetwork()
.withIpamConfig(new ContainerNetwork.Ipam())
.withIpv4Address(customContainer.getCustomNetworkSettings().getIpAddress()); // IP 주소 설정

// 컨테이너 생성
CreateContainerResponse containerResponse = dockerClient.createContainerCmd(imageName)
.withName(containerName)
.withHostConfig(hostConfig)
.withEnv(customContainer.getCustomEnv())
.withCmd(customContainer.getCustomCmd())
.withNetworkMode(customNetwork.getName())
.exec();


dockerClient.connectToNetworkCmd()
.withContainerId(containerResponse.getId())
.withNetworkId(customNetwork.getName())
.withContainerNetwork(containerNetwork)
.exec();

dockerClient.startContainerCmd(containerResponse.getId()).exec();

containerResult.put(CONTAINER_RESULT_STATUS_KEY, CONTAINER_STATUS_SUCCESS);
Expand Down

0 comments on commit 463c2ed

Please sign in to comment.