Services on jobs and existing container (OD-1210)
Closed
bufferUnderrun opened 1 year ago

Hi,

No issue, just technical discussion on how you call docker client from job buildspec

As perfectly describe here, i'm using a service for a CI Database job to test and valid my database script creation and update.

Everything works but i'm wondering :

  • how do you avoid collision between this temporary services (with publish port) and existing container (port already publish) ?
  • what parameters are you passing to docker cli ?

I think you create a private network to avoid this port collision and in addition, allow network connection using container name ?

Thanks for your lights

Robin Shen commented 1 year ago

Yes a private network is defined for each run of the job, and service container is started with network alias specified as service name, which can be accessed as host name. The logic to start service container is as below:

		String image = (String) jobService.get("image");
		docker.clearArgs();
		boolean useProcessIsolation = isUseProcessIsolation(docker, image, nodeOsInfo, jobLogger);

		jobLogger.log("Creating service container...");

		String containerName = network + "-service-" + jobService.get("name");

		docker.clearArgs();
		docker.addArgs("run", "-d", "--name=" + containerName, "--network=" + network,
				"--network-alias=" + jobService.get("name"));

		if (cpuLimit != null)
			docker.addArgs("--cpus", cpuLimit);
		if (memoryLimit != null)
			docker.addArgs("--memory", memoryLimit);

		for (Map.Entry<String, String> entry : ((Map<String, String>) jobService.get("envVars")).entrySet())
			docker.addArgs("--env", entry.getKey() + "=" + entry.getValue());
		if (useProcessIsolation)
			docker.addArgs("--isolation=process");
		docker.addArgs(image);
		if (jobService.get("arguments") != null) {
			for (String token : StringUtils.parseQuoteTokens((String) jobService.get("arguments")))
				docker.addArgs(token);
		}

bufferUnderrun commented 1 year ago

Perfect, thanks !!

bufferUnderrun changed state to 'Closed' 1 year ago
Previous Value Current Value
Open
Closed
issue 1 of 1
Type
Question
Priority
Normal
Assignee
Issue Votes (0)
Watchers (3)
Reference
OD-1210
Please wait...
Page is in error, reload to recover