Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

Add extra-hosts command line option #221

Merged
merged 2 commits into from
Feb 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ orchestrate.py options:
auto)
--expose-headers Sets the Access-Control-Expose-Headers
header.
--extra-hosts Extra hosts for the containers, multiple
hosts can be specified by using a
comma-delimited string, specified in the
form hostname:IP (default [])
--host-directories Mount the specified directory as a data
volume, multiple directories can be
specified by using a comma-delimited string,
Expand Down
9 changes: 7 additions & 2 deletions dockworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

ContainerConfig = namedtuple('ContainerConfig', [
'image', 'command', 'mem_limit', 'cpu_shares', 'container_ip',
'container_port', 'container_user', 'host_network', 'host_directories'
'container_port', 'container_user', 'host_network', 'host_directories',
'extra_hosts'
])

# Number of times to retry API calls before giving up.
Expand Down Expand Up @@ -132,11 +133,15 @@ def create_notebook_server(self, base_path, container_name, container_config):
'mode': permissions
}

extra_hosts = dict(map(lambda h: tuple(h.split(':')),
container_config.extra_hosts))

host_config = dict(
mem_limit=container_config.mem_limit,
network_mode='host' if container_config.host_network else 'bridge',
binds=volume_bindings,
port_bindings=port_bindings
port_bindings=port_bindings,
extra_hosts=extra_hosts
)

host_config = create_host_config(**host_config)
Expand Down
6 changes: 5 additions & 1 deletion orchestrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ def main():
tornado.options.define('user_length', default=12,
help="Length of the unique /user/:id path generated per container"
)
tornado.options.define('extra_hosts', default=[], multiple=True,
help="""Extra hosts for the containers, multiple hosts can be specified
by using a comma-delimited string, specified in the form hostname:IP""")

tornado.options.parse_command_line()
opts = tornado.options.options
Expand Down Expand Up @@ -366,7 +369,8 @@ def main():
container_port=opts.container_port,
container_user=opts.container_user,
host_network=opts.host_network,
host_directories=opts.host_directories
host_directories=opts.host_directories,
extra_hosts=opts.extra_hosts
)

spawner = dockworker.DockerSpawner(docker_host,
Expand Down