Skip to content

Commit

Permalink
feat: raise exception when docker version is below 20.0.0 (#2895)
Browse files Browse the repository at this point in the history
  • Loading branch information
alaeddine-13 committed Jul 9, 2021
1 parent b324d51 commit 7226614
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions jina/excepts.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@ class RoutingTableCyclicError(Exception):

class RuntimeRunForeverEarlyError(Exception):
"""Raised when an error occurs when starting the run_forever of Runtime"""


class DockerVersionError(SystemError):
"""Raised when the docker version is incompatible"""
14 changes: 13 additions & 1 deletion jina/peapods/runtimes/container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..zmq.base import ZMQRuntime
from ...zmq import Zmqlet
from .... import __docker_host__
from ....excepts import BadImageNameError
from ....excepts import BadImageNameError, DockerVersionError
from ...zmq import send_ctrl_message
from ....helper import ArgNamespace, slugify

Expand Down Expand Up @@ -81,6 +81,18 @@ def _docker_run(self, replay: bool = False):

client = docker.from_env()

docker_version = client.version().get('Version')
if not docker_version:
raise DockerVersionError('docker version can not be resolved')

docker_version = tuple(docker_version.split('.'))
# docker daemon versions below 20.0x do not support "host.docker.internal:host-gateway"
if docker_version < ('20',):
raise DockerVersionError(
f'docker version {".".join(docker_version)} is below 20.0.0 and does not '
f'support "host.docker.internal:host-gateway" : https://github.com/docker/cli/issues/2664'
)

if self.args.uses.startswith('docker://'):
uses_img = self.args.uses.replace('docker://', '')
self.logger.debug(f'will use Docker image: {uses_img}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def __init__(self, *args, **kwargs):
def close(self):
pass

def version(self):
return {'Version': '20.0.1'}

@property
def networks(self):
return {'bridge': None}
Expand Down

0 comments on commit 7226614

Please sign in to comment.