<commit_before># Dynamic Ambassador

Dynamic [ambassador pattern](https://docs.docker.com/articles/ambassador_pattern_linking/) based on etcd,
confd, docker-gen and haproxy. This ambassador can be run on a single host but it' designed to be run on
a Docker cluster (like [CoreOS](https://coreos.com/) or [Docker Swarm](https://github.com/docker/swarm))

## Features

- Automated the registration of services and apps running on a Docker host
- Automated the redirection of requests to the service or the app on the true Docker host

This ambassador distinct two kind of container. **App** and **Service** container:

An **app** is an HTTP app accessed with a specific domain name.
It could be a REST API, a web server, etc. Any app relying on HTTP.

A **service** is a TCP service listening on a specific port.
It could be a database, a queuing service, etc. Any TCP app listening on a dedicated PORT with a custom protocol.

This distinction is important, because the mechanism used to proxy requests depends on it.
In a case it is a HTTP proxy, in the other it is a TCP load balancer.

## Usage

Before using this ambassador you need to have a running etcd service. If you don't use a CoreOS cluster you can create an etcd container like this:

```bash
docker run --rm -it -p 4001:4001 -p 7001:7001 microbox/etcd -name=test -addr=172.17.42.1:4001
```

See [here](https://github.com/coreos/etcd/blob/master/Documentation/clustering.md) how to set up a multi-machine cluster.

Start the ambassador container making sure:

- to expose port 80 on the host machine
- to configure the etcd host
- to configure the host IP


```bash
docker run --rm --name dynamic-ambassador -h dynamic-ambassador-1 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e ETCD_HOST=${COREOS_PRIVATE_IPV4}:4001 \
  -e HOST_IP=${COREOS_PRIVATE_IPV4} \
  -p 80:80 \
  ncarlier/dynamic-ambassador
```

On a single host you can also use `make run` to start the container.
With CoreOS you can use the provided unit file:

```bash
fleetctl start ambassador@{1..3}.service
```

Once yours ambassador running you can start yours **apps** and **services**.


`dynamic ambassador` used environment variables into the container to configure **apps** and **services**:
An **app** is registered if the container has a **DOMAIN_NAME** environment variable.
A **service** is registered if the container has a **SERVICE_PORT** environment variable.

> Note: The container **must** also publish a port to be registered by the ambassador

### Sample<commit_msg>doc: Fix docker start command.<commit_after># Dynamic Ambassador

Dynamic [ambassador pattern](https://docs.docker.com/articles/ambassador_pattern_linking/) based on etcd,
confd, docker-gen and haproxy. This ambassador can be run on a single host but it' designed to be run on
a Docker cluster (like [CoreOS](https://coreos.com/) or [Docker Swarm](https://github.com/docker/swarm))

## Features

- Automated the registration of services and apps running on a Docker host
- Automated the redirection of requests to the service or the app on the true Docker host

This ambassador distinct two kind of container. **App** and **Service** container:

An **app** is an HTTP app accessed with a specific domain name.
It could be a REST API, a web server, etc. Any app relying on HTTP.

A **service** is a TCP service listening on a specific port.
It could be a database, a queuing service, etc. Any TCP app listening on a dedicated PORT with a custom protocol.

This distinction is important, because the mechanism used to proxy requests depends on it.
In a case it is a HTTP proxy, in the other it is a TCP load balancer.

## Usage

Before using this ambassador you need to have a running etcd service. If you don't use a CoreOS cluster you can create an etcd container like this:

```bash
docker run --rm -it -p 4001:4001 -p 7001:7001 microbox/etcd -name=test -addr=172.17.42.1:4001
```

See [here](https://github.com/coreos/etcd/blob/master/Documentation/clustering.md) how to set up a multi-machine cluster.

Start the ambassador container making sure:

- to expose port 80 on the host machine
- to configure the etcd host
- to configure the host IP


```bash
docker run --rm --name dynamic-ambassador -h dynamic-ambassador-1 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -e ETCD_HOST=${COREOS_PRIVATE_IPV4}:4001 \
  -e HOST_IP=${COREOS_PRIVATE_IPV4} \
  -p 80:80 \
  ncarlier/dynamic-ambassador
```

On a single host you can also use `make start` to start the container.
With CoreOS you can use the provided unit file:

```bash
fleetctl start ambassador@{1..3}.service
```

Once yours ambassador running you can start yours **apps** and **services**.


`dynamic ambassador` used environment variables into the container to configure **apps** and **services**:
An **app** is registered if the container has a **DOMAIN_NAME** environment variable.
A **service** is registered if the container has a **SERVICE_PORT** environment variable.

> Note: The container **must** also publish a port to be registered by the ambassador

### Sample
{'fraction_non_alphanumeric': 0.0925084008697371, 'fraction_numerical': 0.01699940699743032, 'mean_word_length': 4.184426229508197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7160045', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1411, 'n_words': 697}