Skip to content

Commit

Permalink
Change how docker port mapping works for macos (#1086)
Browse files Browse the repository at this point in the history
* Apply Peter's fix to docker image start up code

* fix port mapping in nodelib
  • Loading branch information
vgrichina authored and ilblackdragon committed Jul 25, 2019
1 parent 0fd0a32 commit a4870f5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions scripts/nodelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def docker_stop_if_exists(name):
except subprocess.CalledProcessError:
pass

"""Checks the ports saved in config.json"""
def get_port(home_dir, net):
config = json.load(open(os.path.join(home_dir, 'config.json')))
p = config[net]['addr'][config[net]['addr'].find(':') + 1:]
return p + ":" + p

"""Runs NEAR core inside the docker container for isolation and easy update with Watchtower."""
def run_docker(image, home_dir, boot_nodes, verbose):
Expand All @@ -96,19 +101,20 @@ def run_docker(image, home_dir, boot_nodes, verbose):
docker_stop_if_exists('nearcore')
# Start nearcore container, mapping home folder and ports.
envs = ['-e', 'BOOT_NODES=%s' % boot_nodes]
rpc_port = get_port(home_dir, 'rpc')
network_port = get_port(home_dir, 'network')
if verbose:
envs.extend(['-e', 'VERBOSE=1'])
subprocess.check_output(['docker', 'run',
'-d', '--network=host', '-v', '%s:/srv/near' % home_dir,
'-d', '-p', rpc_port, '-p', network_port, '-v', '%s:/srv/near' % home_dir,
'--name', 'nearcore', '--restart', 'unless-stopped'] +
envs + [image])
# Start Watchtower that will automatically update the nearcore container when new version appears.
subprocess.check_output(['docker', 'run',
'-d', '--restart', 'unless-stopped', '--name', 'watchtower',
'-v', '/var/run/docker.sock:/var/run/docker.sock',
'v2tec/watchtower', image])
print("To check logs call: docker logs --follow nearcore")

print("Node is running! \nTo check logs call: docker logs --follow nearcore")

"""Runs NEAR core locally."""
def run_local(home_dir, is_release, boot_nodes, verbose):
Expand Down

0 comments on commit a4870f5

Please sign in to comment.