diff --git a/Dockerfile b/Dockerfile index 67b02f8..7d9ddf6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,23 @@ FROM progrium/busybox MAINTAINER Jeff Lindsay -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 [] diff --git a/Makefile b/Makefile index c4e8553..4a1e7f3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ build: - docker build --no-cache -t consul . + docker build -t consul . tag: docker tag consul progrium/consul \ No newline at end of file diff --git a/README.md b/README.md index 4681198..dce3d3f 100644 --- a/README.md +++ b/README.md @@ -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 [::] [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. diff --git a/config/consul.json b/config/consul.json index 99f6ea6..b98eb5a 100644 --- a/config/consul.json +++ b/config/consul.json @@ -1,7 +1,7 @@ { "data_dir": "/data", + "ui_dir": "/ui", "client_addr": "0.0.0.0", - "domain": "cluster", "ports": { "dns": 53 }, diff --git a/start b/start new file mode 100755 index 0000000..0de8d24 --- /dev/null +++ b/start @@ -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 <