mirror of
https://github.com/docker/compose.git
synced 2025-04-07 19:55:07 +02:00
Allow overriding user on the command line
Allow overriding a user on the command line from the one specified in the fig.yaml We are testing on the behavior of how the busybox image is made which is kind of tricky but hopefully that shouln't change. Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com>
This commit is contained in:
parent
200c44cff3
commit
f2f01e207b
@ -276,6 +276,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 USER Run as specified user.
|
||||
--no-deps Don't start linked services.
|
||||
--rm Remove container after run. Ignored in detached mode.
|
||||
-T Disable pseudo-tty allocation. By default `fig run`
|
||||
@ -320,6 +321,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,
|
||||
|
3
tests/fixtures/user-figfile/fig.yml
vendored
Normal file
3
tests/fixtures/user-figfile/fig.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
service:
|
||||
image: busybox:latest
|
||||
command: id
|
@ -1,6 +1,7 @@
|
||||
from __future__ import absolute_import
|
||||
import sys
|
||||
|
||||
from docker.errors import APIError
|
||||
from six import StringIO
|
||||
from mock import patch
|
||||
|
||||
@ -8,6 +9,7 @@ from .testcases import DockerClientTestCase
|
||||
from fig.cli.main import TopLevelCommand
|
||||
|
||||
|
||||
|
||||
class CLITestCase(DockerClientTestCase):
|
||||
def setUp(self):
|
||||
super(CLITestCase, self).setUp()
|
||||
@ -217,6 +219,21 @@ class CLITestCase(DockerClientTestCase):
|
||||
u'/bin/echo helloworld'
|
||||
)
|
||||
|
||||
@patch('dockerpty.start')
|
||||
def test_run_service_with_user_overridden(self, _):
|
||||
name = 'service'
|
||||
self.command.base_dir = 'tests/fixtures/user-figfile'
|
||||
# NOTE(chmou): available in default busybox and has a shell
|
||||
user = 'sshd'
|
||||
args = ['run', '--user', user, name]
|
||||
|
||||
self.command.dispatch(args, None)
|
||||
|
||||
service = self.project.get_service(name)
|
||||
container = service.containers(stopped=True, one_off=True)[0]
|
||||
container.inspect()
|
||||
self.assertEqual(user, container.dictionary['Config']['User'])
|
||||
|
||||
@patch('dockerpty.start')
|
||||
def test_run_service_with_environement_overridden(self, _):
|
||||
name = 'service'
|
||||
|
Loading…
x
Reference in New Issue
Block a user