mirror of https://github.com/docker/compose.git
Merge pull request #5580 from docker/5578-use_cli_exec
Use CLI for interactive exec on all platforms by default
This commit is contained in:
commit
5d4ccafd35
12
Dockerfile
12
Dockerfile
|
@ -17,11 +17,13 @@ RUN set -ex; \
|
|||
; \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN curl https://get.docker.com/builds/Linux/x86_64/docker-1.8.3 \
|
||||
-o /usr/local/bin/docker && \
|
||||
SHA256=f024bc65c45a3778cf07213d26016075e8172de8f6e4b5702bedde06c241650f; \
|
||||
echo "${SHA256} /usr/local/bin/docker" | sha256sum -c - && \
|
||||
chmod +x /usr/local/bin/docker
|
||||
RUN curl -fsSL -o dockerbins.tgz "https://download.docker.com/linux/static/stable/x86_64/docker-17.12.0-ce.tgz" && \
|
||||
SHA256=692e1c72937f6214b1038def84463018d8e320c8eaf8530546c84c2f8f9c767d; \
|
||||
echo "${SHA256} dockerbins.tgz" | sha256sum -c - && \
|
||||
tar xvf dockerbins.tgz docker/docker --strip-components 1 && \
|
||||
mv docker /usr/local/bin/docker && \
|
||||
chmod +x /usr/local/bin/docker && \
|
||||
rm dockerbins.tgz
|
||||
|
||||
# Build Python 2.7.13 from source
|
||||
RUN set -ex; \
|
||||
|
|
|
@ -17,9 +17,11 @@ RUN set -ex; \
|
|||
; \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN curl https://get.docker.com/builds/Linux/armel/docker-1.8.3 \
|
||||
-o /usr/local/bin/docker && \
|
||||
chmod +x /usr/local/bin/docker
|
||||
RUN curl -fsSL -o dockerbins.tgz "https://download.docker.com/linux/static/stable/armhf/docker-17.12.0-ce.tgz" && \
|
||||
tar xvf dockerbins.tgz docker/docker --strip-components 1 && \
|
||||
mv docker /usr/local/bin/docker && \
|
||||
chmod +x /usr/local/bin/docker && \
|
||||
rm dockerbins.tgz
|
||||
|
||||
# Build Python 2.7.13 from source
|
||||
RUN set -ex; \
|
||||
|
|
|
@ -434,6 +434,8 @@ class TopLevelCommand(object):
|
|||
-e, --env KEY=VAL Set environment variables (can be used multiple times,
|
||||
not supported in API < 1.25)
|
||||
"""
|
||||
environment = Environment.from_env_file(self.project_dir)
|
||||
use_cli = not environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
|
||||
index = int(options.get('--index'))
|
||||
service = self.project.get_service(options['SERVICE'])
|
||||
detach = options['-d']
|
||||
|
@ -448,14 +450,14 @@ class TopLevelCommand(object):
|
|||
command = [options['COMMAND']] + options['ARGS']
|
||||
tty = not options["-T"]
|
||||
|
||||
if IS_WINDOWS_PLATFORM and not detach:
|
||||
if IS_WINDOWS_PLATFORM or use_cli and not detach:
|
||||
sys.exit(call_docker(build_exec_command(options, container.id, command)))
|
||||
|
||||
create_exec_options = {
|
||||
"privileged": options["--privileged"],
|
||||
"user": options["--user"],
|
||||
"tty": tty,
|
||||
"stdin": tty,
|
||||
"stdin": True,
|
||||
}
|
||||
|
||||
if docker.utils.version_gte(self.project.client.api_version, '1.25'):
|
||||
|
@ -792,7 +794,7 @@ class TopLevelCommand(object):
|
|||
command = service.options.get('command')
|
||||
|
||||
container_options = build_container_options(options, detach, command)
|
||||
run_one_off_container(container_options, self.project, service, options)
|
||||
run_one_off_container(container_options, self.project, service, options, self.project_dir)
|
||||
|
||||
def scale(self, options):
|
||||
"""
|
||||
|
@ -1199,7 +1201,7 @@ def build_container_options(options, detach, command):
|
|||
return container_options
|
||||
|
||||
|
||||
def run_one_off_container(container_options, project, service, options):
|
||||
def run_one_off_container(container_options, project, service, options, project_dir='.'):
|
||||
if not options['--no-deps']:
|
||||
deps = service.get_dependency_names()
|
||||
if deps:
|
||||
|
@ -1226,10 +1228,13 @@ def run_one_off_container(container_options, project, service, options):
|
|||
if options['--rm']:
|
||||
project.client.remove_container(container.id, force=True, v=True)
|
||||
|
||||
environment = Environment.from_env_file(project_dir)
|
||||
use_cli = not environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
|
||||
|
||||
signals.set_signal_handler_to_shutdown()
|
||||
try:
|
||||
try:
|
||||
if IS_WINDOWS_PLATFORM:
|
||||
if IS_WINDOWS_PLATFORM or use_cli:
|
||||
service.connect_container_to_networks(container)
|
||||
exit_code = call_docker(["start", "--attach", "--interactive", container.id])
|
||||
else:
|
||||
|
|
|
@ -97,7 +97,9 @@ class CLITestCase(unittest.TestCase):
|
|||
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason="requires dockerpty")
|
||||
@mock.patch('compose.cli.main.RunOperation', autospec=True)
|
||||
@mock.patch('compose.cli.main.PseudoTerminal', autospec=True)
|
||||
@mock.patch.dict(os.environ)
|
||||
def test_run_interactive_passes_logs_false(self, mock_pseudo_terminal, mock_run_operation):
|
||||
os.environ['COMPOSE_INTERACTIVE_NO_CLI'] = 'true'
|
||||
mock_client = mock.create_autospec(docker.APIClient)
|
||||
mock_client.api_version = DEFAULT_DOCKER_API_VERSION
|
||||
project = Project.from_config(
|
||||
|
|
Loading…
Reference in New Issue