Skip to content

Commit

Permalink
Fix #959
Browse files Browse the repository at this point in the history
  • Loading branch information
mgubaidullin committed Nov 27, 2023
1 parent 7964206 commit 152156b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ public class DockerService extends DockerServiceUtils {

private static final Logger LOGGER = Logger.getLogger(DockerService.class.getName());

protected static final String NETWORK_NAME = "karavan";

@ConfigProperty(name = "karavan.environment")
String environment;

@ConfigProperty(name = "karavan.docker.network")
String networkName;

@Inject
DockerEventListener dockerEventListener;

Expand Down Expand Up @@ -117,16 +118,16 @@ public void stopListeners() throws IOException {

public void createNetwork() {
if (!getDockerClient().listNetworksCmd().exec().stream()
.filter(n -> n.getName().equals(NETWORK_NAME))
.filter(n -> n.getName().equals(networkName))
.findFirst().isPresent()) {
CreateNetworkResponse res = getDockerClient().createNetworkCmd()
.withName(NETWORK_NAME)
.withName(networkName)
.withDriver("bridge")
.withInternal(false)
.withAttachable(true).exec();
LOGGER.info("Network created: " + NETWORK_NAME);
LOGGER.info("Network created: " + networkName);
} else {
LOGGER.info("Network already exists with name: " + NETWORK_NAME);
LOGGER.info("Network already exists with name: " + networkName);
}
}

Expand Down Expand Up @@ -177,7 +178,7 @@ public Container createContainerFromCompose(DockerComposeService compose, Map<St
}

return createContainer(compose.getContainer_name(), compose.getImage(),
env, compose.getPortsMap(), healthCheck, labels, Map.of(), NETWORK_NAME, restartPolicy);
env, compose.getPortsMap(), healthCheck, labels, Map.of(), networkName, restartPolicy);

} else {
LOGGER.info("Compose Service already exists: " + containers.get(0).getId());
Expand Down Expand Up @@ -219,7 +220,7 @@ public Container createContainer(String name, String image, List<String> env, Ma
.withRestartPolicy(restartPolicy)
.withPortBindings(portBindings)
.withMounts(mounts)
.withNetworkMode(network != null ? network : NETWORK_NAME));
.withNetworkMode(network != null ? network : networkName));

CreateContainerResponse response = createContainerCmd.exec();
LOGGER.info("Container created: " + response.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ karavan.container.statistics.interval=10s
karavan.devmode.image=ghcr.io/apache/camel-karavan-devmode:4.1.0
karavan.maven.cache=

karavan.docker.network=karavan

# Git repository Configuration
karavan.git-repository=http://gitea:3000/karavan/karavan.git
karavan.git-username=karavan
Expand Down

0 comments on commit 152156b

Please sign in to comment.