Commit 0f4e2ae4 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[docker] Implement support for custom network

parent dd0b9f97
......@@ -37,6 +37,7 @@ import os
import requests
import simplejson
import zmq
import docker
import logging
logger = logging.getLogger(__name__)
......@@ -223,6 +224,7 @@ class DockerExecutor(RemoteExecutor):
databases_container = None
datasets_uid = self.data.pop('datasets_uid', None)
network_name = self.data.pop('network_name', 'bridge')
if len(self.databases) > 0:
......@@ -272,6 +274,7 @@ class DockerExecutor(RemoteExecutor):
databases_container = self.host.create_container(databases_environment, cmd)
databases_container.uid = datasets_uid
databases_container.network_name = network_name
# Specify the volumes to mount inside the container
databases_container.add_volume(databases_configuration_path, '/beat/prefix')
......@@ -298,6 +301,14 @@ class DockerExecutor(RemoteExecutor):
cmd = [x if not x.startswith('0.0.0.0:') else '0.0.0.0:%d' % database_port for x in cmd]
databases_container.command = cmd
database_ip = self.host.ip
client = docker.from_env()
for container in client.containers.list():
newtwork_settings = container.attrs['NetworkSettings']
for port, mapping in newtwork_settings['Ports'].items():
if port.startswith('%d' % database_port):
database_ip = newtwork_settings['Networks'][network_name]['IPAddress']
#----- Instantiate the algorithm container
......@@ -314,7 +325,7 @@ class DockerExecutor(RemoteExecutor):
]
if len(self.databases) > 0:
cmd.append('tcp://' + self.host.ip + ':%d' % database_port)
cmd.append('tcp://' + database_ip + ':%d' % database_port)
if logger.getEffectiveLevel() <= logging.DEBUG:
cmd.insert(1, '--debug')
......@@ -322,6 +333,7 @@ class DockerExecutor(RemoteExecutor):
# Creation of the container
algorithm_container = self.host.create_container(processing_environment, cmd)
algorithm_container.uid = datasets_uid
algorithm_container.network_name = network_name
# Volumes
algorithm_container.add_volume(configuration_path, '/beat/prefix')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment