aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRagnis Armus <ragnis@armus.ee>2020-02-26 19:19:49 +0200
committerRagnis Armus <ragnis@armus.ee>2020-07-18 14:59:29 +0300
commitf4cf4ca80cb25de2b00bcf4fb23ab54d89a30b64 (patch)
treeac29ba21a9816a78259281e77e1e780416ac1355
parentbfb346fb24fcbf00b38c71d4763bdc64d7b4a4c2 (diff)
Export host address
-rwxr-xr-xdpm19
1 files changed, 19 insertions, 0 deletions
diff --git a/dpm b/dpm
index 3bebdc7..1a7b818 100755
--- a/dpm
+++ b/dpm
@@ -153,6 +153,21 @@ def run_for_output(args):
return cp
+def find_docker_network_gateway(name):
+ out = run_for_output(['docker', 'network', 'inspect', name]).stdout
+ networks = json.loads(out)
+ gw = None
+
+ for net in networks:
+ try:
+ gw = net['IPAM']['Config'][0]['Gateway']
+ except:
+ pass
+
+ if gw is not None:
+ return gw
+
+
def list_docker_things(kind, filters):
cmd = ['docker'] + kind + ['--no-trunc', '-q']
@@ -268,6 +283,10 @@ def run_container(name, image, bg, cmd):
args.extend(('--volume', image['workdir'] + '/node_modules'))
+ gw = find_docker_network_gateway('bridge')
+ if gw is not None:
+ args.extend(('--add-host', 'docker-host.localhost:' + gw))
+
exec(['docker', 'run'] + args + [image['id']] + cmd)