From 5fb7e4b0f19464181019a28e046ca9d6abdf0375 Mon Sep 17 00:00:00 2001 From: Christophe Mehay Date: Tue, 22 Sep 2015 22:11:04 +0200 Subject: [PATCH] docker-compose example and better readme --- README.md | 9 ++++-- docker-compose.yaml | 10 +++++++ docker/__init__.py | 0 docker/docker.py | 70 --------------------------------------------- 4 files changed, 16 insertions(+), 73 deletions(-) create mode 100644 docker-compose.yaml delete mode 100644 docker/__init__.py delete mode 100644 docker/docker.py diff --git a/README.md b/README.md index 57f010f..f8c1aeb 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ -h1. docker-tor-hidden-service +# docker-tor-hidden-service Create a tor hidden service with a link ``` -$ # run a container with an network application +# run a container with an network application $ docker run -d --name hello_world tutum/hello_world -$ # and just link it to this container + +# and just link it to this container $ docker run -ti --link hello_world goldy/tor-hidden-service ``` @@ -16,3 +17,5 @@ To keep onion keys, just mount volume `/var/lib/tor/hidden_service/` ``` $ docker run -ti --link something --volume /path/to/keys:/var/lib/tor/hidden_service/ goldy/tor-hidden-service ``` + +Look at the `docker-compose.yml` file to see own to use it. diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..3a04024 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,10 @@ +# docker-compose.yml example + +tor: + image: goldy/tor-hidden-service + links: + - hello + +hello: + image: tutum/hello-world + hostname: hello-world diff --git a/docker/__init__.py b/docker/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/docker/docker.py b/docker/docker.py deleted file mode 100644 index 1329280..0000000 --- a/docker/docker.py +++ /dev/null @@ -1,70 +0,0 @@ -#! /usr/bin/env python3 - -import os -import json -import re - -""" - get_docker_links is a kiss module which return a dict of links - in a docker container, or a formated json if you run it -""" - -def _find_ports(link_name): - rtn = {} - p = re.compile('^{link}_PORT_(\d*)_(UDP|TCP)$'.format(link=link_name)) - for key in os.environ: - m = p.match(key) - if m: - rtn[m.group(1)] = { - "protocol": m.group(2).lower(), - } - return rtn - -def _find_env(link_name): - rtn = {} - p = re.compile('^{link}_ENV_(.*)$'.format(link=link_name)) - for key, value in os.environ.items(): - m = p.match(key) - if m: - rtn[m.group(1)] = value - return rtn - -def get_links(*args): - """ - List all links and return dictionnay with link name, ip address, - ports and protocols. - """ - rtn = {} - nb_args = len(args) - # Read hosts file - with open('/etc/hosts') as hosts: - for line in hosts: - split = line.split() - if len(split) != 3: - continue - # Check if entry is a link - link_ip = split[0] - link_name_env = split[1].upper() - link_name = split[1] - env_var = "{link_name}_NAME".format(link_name=link_name_env) - if nb_args and link_name not in args: - continue - if env_var in os.environ: - network = os.environ[env_var].split(':') - rtn[link_name] = { - "ip": link_ip, - "ports": _find_ports(link_name_env), - "environment": _find_env(link_name_env) - } - return rtn - -def to_json(*args): - print(json.dumps(get_links(*args), - sort_keys=True, - indent=4, - separators=(',', ': ') - )) - - -if __name__ == '__main__': - to_json()