Merge pull request #971 from IanVS/master

Provide user override option on command line
This commit is contained in:
Daniel Nephin 2015-03-11 10:16:43 -04:00
commit c23189a5fa
4 changed files with 32 additions and 0 deletions

View File

@ -275,6 +275,7 @@ class TopLevelCommand(Command):
new container name.
--entrypoint CMD Override the entrypoint of the image.
-e KEY=VAL Set an environment variable (can be used multiple times)
-u, --user="" Run as specified username or uid
--no-deps Don't start linked services.
--rm Remove container after run. Ignored in detached mode.
--service-ports Run command with the service's ports enabled and mapped
@ -322,6 +323,10 @@ class TopLevelCommand(Command):
if options['--entrypoint']:
container_options['entrypoint'] = options.get('--entrypoint')
if options['--user']:
container_options['user'] = options.get('--user')
container = service.create_container(
one_off=True,
insecure_registry=insecure_registry,

View File

@ -0,0 +1,4 @@
service:
image: busybox:latest
user: notauser
command: id

View File

@ -231,6 +231,28 @@ class CLITestCase(DockerClientTestCase):
u'/bin/echo helloworld'
)
@patch('dockerpty.start')
def test_run_service_with_user_overridden(self, _):
self.command.base_dir = 'tests/fixtures/user-composefile'
name = 'service'
user = 'sshd'
args = ['run', '--user={}'.format(user), name]
self.command.dispatch(args, None)
service = self.project.get_service(name)
container = service.containers(stopped=True, one_off=True)[0]
self.assertEqual(user, container.get('Config.User'))
@patch('dockerpty.start')
def test_run_service_with_user_overridden_short_form(self, _):
self.command.base_dir = 'tests/fixtures/user-composefile'
name = 'service'
user = 'sshd'
args = ['run', '-u', user, name]
self.command.dispatch(args, None)
service = self.project.get_service(name)
container = service.containers(stopped=True, one_off=True)[0]
self.assertEqual(user, container.get('Config.User'))
@patch('dockerpty.start')
def test_run_service_with_environement_overridden(self, _):
name = 'service'

View File

@ -120,6 +120,7 @@ class CLITestCase(unittest.TestCase):
'SERVICE': 'service',
'COMMAND': None,
'-e': ['BAR=NEW', 'OTHER=THREE'],
'--user': None,
'--no-deps': None,
'--allow-insecure-ssl': None,
'-d': True,