Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion airflow/operators/docker_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class DockerOperator(BaseOperator):
:type user: int or str
:param volumes: List of volumes to mount into the container, e.g.
``['/host/path:/container/path', '/host/path2:/container/path2:ro']``.
:param working_dir: Working directory to set on the container (equivalent to the -w switch
the docker client)
:type working_dir: str
:param xcom_push: Does the stdout will be pushed to the next step using XCom.
The default is False.
:type xcom_push: bool
Expand Down Expand Up @@ -99,6 +102,7 @@ def __init__(
tmp_dir='/tmp/airflow',
user=None,
volumes=None,
working_dir=None,
xcom_push=False,
xcom_all=False,
*args,
Expand All @@ -122,6 +126,7 @@ def __init__(
self.tmp_dir = tmp_dir
self.user = user
self.volumes = volumes or []
self.working_dir = working_dir
self.xcom_push_flag = xcom_push
self.xcom_all = xcom_all

Expand Down Expand Up @@ -169,7 +174,8 @@ def execute(self, context):
network_mode=self.network_mode),
image=image,
mem_limit=self.mem_limit,
user=self.user
user=self.user,
working_dir=self.working_dir
)
self.cli.start(self.container['Id'])

Expand Down
7 changes: 5 additions & 2 deletions tests/operators/docker_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def test_execute(self, client_class_mock, mkdtemp_mock):

operator = DockerOperator(api_version='1.19', command='env', environment={'UNIT': 'TEST'},
image='ubuntu:latest', network_mode='bridge', owner='unittest',
task_id='unittest', volumes=['/host/path:/container/path'])
task_id='unittest', volumes=['/host/path:/container/path'],
working_dir='/container/path')
operator.execute(None)

client_class_mock.assert_called_with(base_url='unix://var/run/docker.sock', tls=None,
Expand All @@ -65,7 +66,9 @@ def test_execute(self, client_class_mock, mkdtemp_mock):
},
host_config=host_config,
image='ubuntu:latest',
mem_limit=None, user=None)
mem_limit=None, user=None,
working_dir='/container/path'
)
client_mock.create_host_config.assert_called_with(binds=['/host/path:/container/path',
'/mkdtemp:/tmp/airflow'],
network_mode='bridge')
Expand Down