Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

Commit

Permalink
using consul 0.3.0, now installs the webui, returned to consul TLD, i…
Browse files Browse the repository at this point in the history
…ncluding bash and setting it as the intended SHELL, and added a docker run convenience command generator
  • Loading branch information
progrium committed Jul 3, 2014
1 parent 7b94cd0 commit 028923e
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 10 deletions.
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
FROM progrium/busybox
MAINTAINER Jeff Lindsay <[email protected]>

ADD https://dl.bintray.com/mitchellh/consul/0.2.1_linux_amd64.zip /tmp/consul.zip
RUN cd /bin && unzip /tmp/consul.zip && chmod +x /bin/consul
ADD https://dl.bintray.com/mitchellh/consul/0.3.0_linux_amd64.zip /tmp/consul.zip
RUN cd /bin && unzip /tmp/consul.zip && chmod +x /bin/consul && rm /tmp/consul.zip

RUN opkg-install curl
ADD https://dl.bintray.com/mitchellh/consul/0.3.0_web_ui.zip /tmp/webui.zip
RUN cd /tmp && unzip /tmp/webui.zip && mv dist /ui && rm /tmp/webui.zip

RUN opkg-install curl bash

ADD ./config /config/
ONBUILD ADD ./config /config/

ADD ./start /bin/start

EXPOSE 8300 8301 8301/udp 8302 8302/udp 8400 8500 53/udp
VOLUME ["/data"]

ENTRYPOINT ["/bin/consul", "agent", "-config-dir=/config"]
ENV SHELL /bin/bash

ENTRYPOINT ["/bin/start"]
CMD []
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

build:
docker build --no-cache -t consul .
docker build -t consul .

tag:
docker tag consul progrium/consul
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,57 @@ Once the third host is running, you want to go back to the second host, kill the

## Opinionated Configuration

#### DNS
#### Convenience runner command

Since the `docker run` command to start in production is so long, a command is available to generate this for you. Running with `cmd:run <advertise-ip>[::<join-ip>] [docker run args...]` will output an opinionated, but customizable `docker run` command you can run in a subshell. For example:

$ docker run --rm progrium/consul cmd:run 10.0.1.1 -d

Outputs:

eval docker run --name consul -h $HOSTNAME \
-p 10.0.1.1:8300:8300 \
-p 10.0.1.1:8301:8301 \
-p 10.0.1.1:8301:8301/udp \
-p 10.0.1.1:8302:8302 \
-p 10.0.1.1:8302:8302/udp \
-p 10.0.1.1:8400:8400 \
-p 10.0.1.1:8500:8500 \
-p 172.17.42.1:53:53/udp \
-d \
progrium/consul -server -advertise 10.0.1.1 -bootstrap

By design, it will set the hostname of the container to your host hostname, it will name the container `consul` (though this can be overridden), it will bind port 53 to the Docker bridge, and the rest of the ports on the advertise IP. If no join IP is provided, it runs in bootstrap mode. Here is another example, specifying a join IP and setting more docker run arguments:

This container was designed assuming you'll be using it for DNS on your other containers. So it listens on port 53 inside the container to be more compatible and accessible via linking. It also has DNS recursive queries enabled, using the Google nameservers.
$ docker run --rm progrium/consul cmd:run 10.0.1.1::10.0.1.2 -d -v /mnt:/data

Outputs:

eval docker run --name consul -h $HOSTNAME \
-p 10.0.1.1:8300:8300 \
-p 10.0.1.1:8301:8301 \
-p 10.0.1.1:8301:8301/udp \
-p 10.0.1.1:8302:8302 \
-p 10.0.1.1:8302:8302/udp \
-p 10.0.1.1:8400:8400 \
-p 10.0.1.1:8500:8500 \
-p 172.17.42.1:53:53/udp \
-d -v /mnt:/data \
progrium/consul -server -advertise 10.0.1.1 -join 10.0.1.2

You can simply wrap the cmd:run output in a subshell. Here is what you can run to see it work without detached mode:

$ $(docker run --rm progrium/consul cmd:run 127.0.0.1)

#### DNS

It also assumes DNS is a primary means of service discovery for your entire system. It uses `cluster` as the top level domain instead of `consul` just as a more general / accurate naming ontology.
This container was designed assuming you'll be using it for DNS on your other containers. So it listens on port 53 inside the container to be more compatible and accessible via linking. It also has DNS recursive queries enabled, using the Google 8.8.8.8 nameserver.

#### Runtime Configuration

Although you can extend this image to add configuration files to define services and checks, this container was designed for environments where services and checks can be configured at runtime via the HTTP API.

It's recommended you keep your check logic simple, such as using inline `curl` or `ping` commands. Otherwise, keep in mind the default shell is `ash`.
It's recommended you keep your check logic simple, such as using inline `curl` or `ping` commands. Otherwise, keep in mind the default shell is Bash, but you're running in Busybox.

If you absolutely need to customize startup configuration, you can extend this image by making a new Dockerfile based on this one and having a `config` directory containing config JSON files. They will be added to the image you build via ONBUILD hooks. You can also add packages with `opkg`. See [docs on the Busybox image](https://github.com/progrium/busybox) for more info.

Expand Down
2 changes: 1 addition & 1 deletion config/consul.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"data_dir": "/data",
"ui_dir": "/ui",
"client_addr": "0.0.0.0",
"domain": "cluster",
"ports": {
"dns": 53
},
Expand Down
42 changes: 42 additions & 0 deletions start
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

readonly IMAGE="progrium/consul"

cmd-run() {
local ip_def="$1"; shift
local args="$@"

declare external_ip join_ip bridge_ip run_mode

IFS=':' read external_ip join_ip <<< "${ip_def/::/:}"
if [[ -z "$join_ip" ]]; then
run_mode="-bootstrap"
else
run_mode="-join $join_ip"
fi

bridge_ip="$(ip ro | grep ^default | awk '{print $3}')"
cat <<EOF
eval docker run --name consul -h \$HOSTNAME \
-p $external_ip:8300:8300 \
-p $external_ip:8301:8301 \
-p $external_ip:8301:8301/udp \
-p $external_ip:8302:8302 \
-p $external_ip:8302:8302/udp \
-p $external_ip:8400:8400 \
-p $external_ip:8500:8500 \
-p $bridge_ip:53:53/udp \
$args \
$IMAGE -server -advertise $external_ip $run_mode
EOF
}

main() {
set -eo pipefail
case "$1" in
cmd:run) shift; cmd-run $@;;
*) /bin/consul agent -config-dir=/config $@;;
esac
}

main "$@"

0 comments on commit 028923e

Please sign in to comment.