Fix interactive run with networking

Make sure we connect the container to all required networks *after*
starting the container and *before* hijacking the terminal.

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
Aanand Prasad 2016-01-21 18:34:18 +00:00
parent 09dbc7b4cb
commit f3e55568d1
3 changed files with 8 additions and 6 deletions

View File

@ -41,7 +41,7 @@ from .utils import yesno
if not IS_WINDOWS_PLATFORM:
import dockerpty
from dockerpty.pty import PseudoTerminal
log = logging.getLogger(__name__)
console_handler = logging.StreamHandler(sys.stderr)
@ -709,8 +709,10 @@ def run_one_off_container(container_options, project, service, options):
signals.set_signal_handler_to_shutdown()
try:
try:
dockerpty.start(project.client, container.id, interactive=not options['-T'])
service.connect_container_to_networks(container)
pty = PseudoTerminal(project.client, container.id, interactive=not options['-T'])
sockets = pty.sockets()
service.start_container(container)
pty.start(sockets)
exit_code = container.wait()
except signals.ShutdownException:
project.client.stop(container.id)

View File

@ -1,8 +1,8 @@
PyYAML==3.11
cached-property==1.2.0
dockerpty==0.3.4
docopt==0.6.1
enum34==1.0.4
git+https://github.com/d11wtq/dockerpty.git@29b1394108b017ef3e3deaf00604a9eb99880d5e#egg=dockerpty
git+https://github.com/docker/docker-py.git@master#egg=docker-py
jsonschema==2.5.1
requests==2.7.0

View File

@ -72,8 +72,8 @@ class CLITestCase(unittest.TestCase):
TopLevelCommand().dispatch(['help', 'nonexistent'], None)
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason="requires dockerpty")
@mock.patch('compose.cli.main.dockerpty', autospec=True)
def test_run_with_environment_merged_with_options_list(self, mock_dockerpty):
@mock.patch('compose.cli.main.PseudoTerminal', autospec=True)
def test_run_with_environment_merged_with_options_list(self, mock_pseudo_terminal):
command = TopLevelCommand()
mock_client = mock.create_autospec(docker.Client)
mock_project = mock.Mock(client=mock_client)