Skip to content

Commit

Permalink
[AIRFLOW-3025] Enable specifying dns and dns_search options for Docke…
Browse files Browse the repository at this point in the history
…rOperator (#3860)

Enable specifying dns and dns_search options for DockerOperator
  • Loading branch information
kodieg authored and ashb committed Oct 22, 2018
1 parent ad9c384 commit d6b59bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 11 additions & 1 deletion airflow/operators/docker_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class DockerOperator(BaseOperator):
This value gets multiplied with 1024. See
https://docs.docker.com/engine/reference/run/#cpu-share-constraint
:type cpus: float
:param dns: Docker custom DNS servers
:type dns: list of strings
:param dns_search: Docker custom DNS search domain
:type dns_search: list of strings
:param docker_url: URL of the host running the docker daemon.
Default is unix://var/run/docker.sock
:type docker_url: str
Expand Down Expand Up @@ -127,13 +131,17 @@ def __init__(
xcom_push=False,
xcom_all=False,
docker_conn_id=None,
dns=None,
dns_search=None,
*args,
**kwargs):

super(DockerOperator, self).__init__(*args, **kwargs)
self.api_version = api_version
self.command = command
self.cpus = cpus
self.dns = dns
self.dns_search = dns_search
self.docker_url = docker_url
self.environment = environment or {}
self.force_pull = force_pull
Expand Down Expand Up @@ -203,7 +211,9 @@ def execute(self, context):
host_config=self.cli.create_host_config(
binds=self.volumes,
network_mode=self.network_mode,
shm_size=self.shm_size),
shm_size=self.shm_size,
dns=self.dns,
dns_search=self.dns_search),
image=image,
mem_limit=self.mem_limit,
user=self.user,
Expand Down
4 changes: 3 additions & 1 deletion tests/operators/docker_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def test_execute(self, client_class_mock, mkdtemp_mock):
client_mock.create_host_config.assert_called_with(binds=['/host/path:/container/path',
'/mkdtemp:/tmp/airflow'],
network_mode='bridge',
shm_size=1000)
shm_size=1000,
dns=None,
dns_search=None)
client_mock.images.assert_called_with(name='ubuntu:latest')
client_mock.logs.assert_called_with(container='some_id', stream=True)
client_mock.pull.assert_called_with('ubuntu:latest', stream=True)
Expand Down

0 comments on commit d6b59bc

Please sign in to comment.