Skip to content

Commit

Permalink
Fix docker#1610: #run command exits if there is any DockerApi connect…
Browse files Browse the repository at this point in the history
…ive issue

When #docker-compose #up command is used, it may attach to user #tty to print logs.
During an #up session, if #docker daemon is restarted (any reason), #docker-compose
is unable to reconnect to #docker Api (#docker-compose should has a #reconnect feature).
it will print ConnectionError exception to #stdout, and keeps running without any
useful information, while all project containers actually exit.

This fix is useful when you use #supervisor to launch "#docker-compose up".

Signed-off-by: Ky-Anh Huynh <[email protected]>
  • Loading branch information
icy committed Jul 19, 2015
1 parent 4b4c4f3 commit aa6851d
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions compose/cli/log_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .multiplexer import Multiplexer, STOP
from . import colors
from .utils import split_buffer

from requests.exceptions import ConnectionError

class LogPrinter(object):
def __init__(self, containers, attach_params=None, output=sys.stdout, monochrome=False):
Expand Down Expand Up @@ -52,16 +52,20 @@ def no_color(text):
return generators

def _make_log_generator(self, container, color_fn):
prefix = color_fn(self._generate_prefix(container)).encode('utf-8')
# Attach to container before log printer starts running
line_generator = split_buffer(self._attach(container), '\n')

for line in line_generator:
yield prefix + line

exit_code = container.wait()
yield color_fn("%s exited with code %s\n" % (container.name, exit_code))
yield STOP
try:
prefix = color_fn(self._generate_prefix(container)).encode('utf-8')
# Attach to container before log printer starts running
line_generator = split_buffer(self._attach(container), '\n')

for line in line_generator:
yield prefix + line

exit_code = container.wait()
yield color_fn("%s exited with code %s\n" % (container.name, exit_code))
yield STOP
except ConnectionError as e:
yield color_fn("%s: Unable to connect to Docker Api. Aborting.\n" % (container.name))
yield STOP

def _generate_prefix(self, container):
"""
Expand Down

0 comments on commit aa6851d

Please sign in to comment.