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
5 changes: 5 additions & 0 deletions fig/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def run(self, options):
allocates a TTY.
--rm Remove container after run. Ignored in detached mode.
--no-deps Don't start linked services.
-w WORKDIR Working directory inside the container.
"""

service = self.project.get_service(options['SERVICE'])
Expand All @@ -233,6 +234,8 @@ def run(self, options):
if options['-d'] or options['-T'] or not sys.stdin.isatty():
tty = False

workdir = options['-w']

if options['COMMAND']:
command = [options['COMMAND']] + options['ARGS']
else:
Expand All @@ -243,6 +246,8 @@ def run(self, options):
'tty': tty,
'stdin_open': not options['-d'],
}
if workdir:
container_options['working_dir'] = workdir
container = service.create_container(one_off=True, **container_options)
if options['-d']:
service.start_container(container, ports=None, one_off=True)
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ def test_run_does_not_recreate_linked_containers(self, __):

self.assertEqual(old_ids, new_ids)

@patch('dockerpty.start')
def test_run_with_working_dir(self, __):
self.command.base_dir = 'tests/fixtures/links-figfile'

for c in self.command.project.containers(stopped=True, one_off=True):
c.remove()

self.command.dispatch(['run', '-w', '/tmp', 'web', '/bin/pwd'], None)
service = self.command.project.get_service('web')
containers = service.containers(stopped=True, one_off=True)

self.assertEqual(
[c.inspect()['Config']['WorkingDir'] for c in containers],
[u'/tmp'],
)

@patch('dockerpty.start')
def test_run_without_command(self, __):
self.command.base_dir = 'tests/fixtures/commands-figfile'
Expand Down