Skip to content

Commit 39cc181

Browse files
kodiegChris Fei
kodieg
authored and
Chris Fei
committed
Enable specifying dns and dns_search options for DockerOperator (apache#3860)
Enable specifying dns and dns_search options for DockerOperator
1 parent 3fecb28 commit 39cc181

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

airflow/operators/docker_operator.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class DockerOperator(BaseOperator):
5353
This value gets multiplied with 1024. See
5454
https://docs.docker.com/engine/reference/run/#cpu-share-constraint
5555
:type cpus: float
56+
:param dns: Docker custom DNS servers
57+
:type dns: list of strings
58+
:param dns_search: Docker custom DNS search domain
59+
:type dns_search: list of strings
5660
:param docker_url: URL of the host running the docker daemon.
5761
Default is unix://var/run/docker.sock
5862
:type docker_url: str
@@ -127,13 +131,17 @@ def __init__(
127131
xcom_push=False,
128132
xcom_all=False,
129133
docker_conn_id=None,
134+
dns=None,
135+
dns_search=None,
130136
*args,
131137
**kwargs):
132138

133139
super(DockerOperator, self).__init__(*args, **kwargs)
134140
self.api_version = api_version
135141
self.command = command
136142
self.cpus = cpus
143+
self.dns = dns
144+
self.dns_search = dns_search
137145
self.docker_url = docker_url
138146
self.environment = environment or {}
139147
self.force_pull = force_pull
@@ -203,7 +211,9 @@ def execute(self, context):
203211
host_config=self.cli.create_host_config(
204212
binds=self.volumes,
205213
network_mode=self.network_mode,
206-
shm_size=self.shm_size),
214+
shm_size=self.shm_size,
215+
dns=self.dns,
216+
dns_search=self.dns_search),
207217
image=image,
208218
mem_limit=self.mem_limit,
209219
user=self.user,

tests/operators/docker_operator.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def test_execute(self, client_class_mock, mkdtemp_mock):
7777
client_mock.create_host_config.assert_called_with(binds=['/host/path:/container/path',
7878
'/mkdtemp:/tmp/airflow'],
7979
network_mode='bridge',
80-
shm_size=1000)
80+
shm_size=1000,
81+
dns=None,
82+
dns_search=None)
8183
client_mock.images.assert_called_with(name='ubuntu:latest')
8284
client_mock.logs.assert_called_with(container='some_id', stream=True)
8385
client_mock.pull.assert_called_with('ubuntu:latest', stream=True)

0 commit comments

Comments
 (0)