mirror of https://github.com/docker/compose.git
Fix bugs with entrypoint/command in docker-compose run
- When no command is passed but `--entrypoint` is, set Cmd to `[]` - When command is a single empty string, set Cmd to `[""]` Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
1e60030b94
commit
593d1aeb09
|
@ -668,8 +668,10 @@ class TopLevelCommand(object):
|
||||||
'can not be used together'
|
'can not be used together'
|
||||||
)
|
)
|
||||||
|
|
||||||
if options['COMMAND']:
|
if options['COMMAND'] is not None:
|
||||||
command = [options['COMMAND']] + options['ARGS']
|
command = [options['COMMAND']] + options['ARGS']
|
||||||
|
elif options['--entrypoint'] is not None:
|
||||||
|
command = []
|
||||||
else:
|
else:
|
||||||
command = service.options.get('command')
|
command = service.options.get('command')
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ from __future__ import unicode_literals
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shlex
|
|
||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
@ -983,16 +982,54 @@ class CLITestCase(DockerClientTestCase):
|
||||||
[u'/bin/true'],
|
[u'/bin/true'],
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_run_service_with_entrypoint_overridden(self):
|
def test_run_service_with_dockerfile_entrypoint(self):
|
||||||
self.base_dir = 'tests/fixtures/dockerfile_with_entrypoint'
|
self.base_dir = 'tests/fixtures/entrypoint-dockerfile'
|
||||||
name = 'service'
|
self.dispatch(['run', 'test'])
|
||||||
self.dispatch(['run', '--entrypoint', '/bin/echo', name, 'helloworld'])
|
container = self.project.containers(stopped=True, one_off=OneOffFilter.only)[0]
|
||||||
service = self.project.get_service(name)
|
assert container.get('Config.Entrypoint') == ['printf']
|
||||||
container = service.containers(stopped=True, one_off=OneOffFilter.only)[0]
|
assert container.get('Config.Cmd') == ['default', 'args']
|
||||||
self.assertEqual(
|
|
||||||
shlex.split(container.human_readable_command),
|
def test_run_service_with_dockerfile_entrypoint_overridden(self):
|
||||||
[u'/bin/echo', u'helloworld'],
|
self.base_dir = 'tests/fixtures/entrypoint-dockerfile'
|
||||||
)
|
self.dispatch(['run', '--entrypoint', 'echo', 'test'])
|
||||||
|
container = self.project.containers(stopped=True, one_off=OneOffFilter.only)[0]
|
||||||
|
assert container.get('Config.Entrypoint') == ['echo']
|
||||||
|
assert not container.get('Config.Cmd')
|
||||||
|
|
||||||
|
def test_run_service_with_dockerfile_entrypoint_and_command_overridden(self):
|
||||||
|
self.base_dir = 'tests/fixtures/entrypoint-dockerfile'
|
||||||
|
self.dispatch(['run', '--entrypoint', 'echo', 'test', 'foo'])
|
||||||
|
container = self.project.containers(stopped=True, one_off=OneOffFilter.only)[0]
|
||||||
|
assert container.get('Config.Entrypoint') == ['echo']
|
||||||
|
assert container.get('Config.Cmd') == ['foo']
|
||||||
|
|
||||||
|
def test_run_service_with_compose_file_entrypoint(self):
|
||||||
|
self.base_dir = 'tests/fixtures/entrypoint-composefile'
|
||||||
|
self.dispatch(['run', 'test'])
|
||||||
|
container = self.project.containers(stopped=True, one_off=OneOffFilter.only)[0]
|
||||||
|
assert container.get('Config.Entrypoint') == ['printf']
|
||||||
|
assert container.get('Config.Cmd') == ['default', 'args']
|
||||||
|
|
||||||
|
def test_run_service_with_compose_file_entrypoint_overridden(self):
|
||||||
|
self.base_dir = 'tests/fixtures/entrypoint-composefile'
|
||||||
|
self.dispatch(['run', '--entrypoint', 'echo', 'test'])
|
||||||
|
container = self.project.containers(stopped=True, one_off=OneOffFilter.only)[0]
|
||||||
|
assert container.get('Config.Entrypoint') == ['echo']
|
||||||
|
assert not container.get('Config.Cmd')
|
||||||
|
|
||||||
|
def test_run_service_with_compose_file_entrypoint_and_command_overridden(self):
|
||||||
|
self.base_dir = 'tests/fixtures/entrypoint-composefile'
|
||||||
|
self.dispatch(['run', '--entrypoint', 'echo', 'test', 'foo'])
|
||||||
|
container = self.project.containers(stopped=True, one_off=OneOffFilter.only)[0]
|
||||||
|
assert container.get('Config.Entrypoint') == ['echo']
|
||||||
|
assert container.get('Config.Cmd') == ['foo']
|
||||||
|
|
||||||
|
def test_run_service_with_compose_file_entrypoint_and_empty_string_command(self):
|
||||||
|
self.base_dir = 'tests/fixtures/entrypoint-composefile'
|
||||||
|
self.dispatch(['run', '--entrypoint', 'echo', 'test', ''])
|
||||||
|
container = self.project.containers(stopped=True, one_off=OneOffFilter.only)[0]
|
||||||
|
assert container.get('Config.Entrypoint') == ['echo']
|
||||||
|
assert container.get('Config.Cmd') == ['']
|
||||||
|
|
||||||
def test_run_service_with_user_overridden(self):
|
def test_run_service_with_user_overridden(self):
|
||||||
self.base_dir = 'tests/fixtures/user-composefile'
|
self.base_dir = 'tests/fixtures/user-composefile'
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
service:
|
|
||||||
build: .
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
version: "2"
|
||||||
|
services:
|
||||||
|
test:
|
||||||
|
image: busybox
|
||||||
|
entrypoint: printf
|
||||||
|
command: default args
|
|
@ -1,3 +1,4 @@
|
||||||
FROM busybox:latest
|
FROM busybox:latest
|
||||||
LABEL com.docker.compose.test_image=true
|
LABEL com.docker.compose.test_image=true
|
||||||
ENTRYPOINT echo "From prebuilt entrypoint"
|
ENTRYPOINT ["printf"]
|
||||||
|
CMD ["default", "args"]
|
|
@ -0,0 +1,4 @@
|
||||||
|
version: "2"
|
||||||
|
services:
|
||||||
|
test:
|
||||||
|
build: .
|
Loading…
Reference in New Issue