From 665455d319a62b4cff9ca80f3ff4f1c43505aa4f Mon Sep 17 00:00:00 2001
From: Joona Hoikkala <joohoi@users.noreply.github.com>
Date: Mon, 22 Jan 2018 12:35:07 +0200
Subject: [PATCH] Docker instructions and configuration (#33)

* Added dockerfile

* Docker configuration

* Added Docker images, composer configuration and documentation
---
 Dockerfile         | 20 ++++++++++++++++++++
 README.md          | 29 +++++++++++++++++++++++++++++
 config.cfg         |  7 ++++---
 docker-compose.yml | 14 ++++++++++++++
 4 files changed, 67 insertions(+), 3 deletions(-)
 create mode 100644 Dockerfile
 create mode 100644 docker-compose.yml

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..227e977
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,20 @@
+FROM golang:1.9.2-alpine AS builder
+LABEL maintainer="joona@kuori.org"
+
+RUN apk add --update gcc musl-dev git
+
+RUN go get github.com/joohoi/acme-dns
+WORKDIR /go/src/github.com/joohoi/acme-dns
+RUN CGO_ENABLED=1 go build
+
+FROM alpine:latest
+
+WORKDIR /root/
+COPY --from=builder /go/src/github.com/joohoi/acme-dns .
+RUN mkdir -p /etc/acme-dns
+RUN mkdir -p /var/lib/acme-dns
+RUN rm -rf ./config.cfg
+
+VOLUME ["/etc/acme-dns", "/var/lib/acme-dns"]
+ENTRYPOINT ["./acme-dns"]
+EXPOSE 53 80 443
diff --git a/README.md b/README.md
index f0f460e..41070e8 100644
--- a/README.md
+++ b/README.md
@@ -117,6 +117,35 @@ Check out how in the INSTALL section.
 
 5) Run acme-dns. Please note that acme-dns needs to open a privileged port (53, domain), so it needs to be run with elevated privileges.
 
+## Using Docker
+
+1) Pull the latest acme-dns Docker image: `docker pull joohoi/acme-dns` 
+
+2) Create directories: `config` for the configuration file, and `data` for the sqlite3 database.
+
+3) Copy [configuration template](https://raw.githubusercontent.com/joohoi/acme-dns/master/config.cfg) to `config/config.cfg` 
+
+4) Modify the config.cfg to suit your needs.
+
+5) Run Docker, this example expects that you have `port = "80"` in your config.cfg:
+```
+docker run --rm --name acmedns                 \
+ -p 53:53                                      \
+ -p 80:80                                      \
+ -v /path/to/your/config:/etc/acme-dns:ro      \
+ -v /path/to/your/data:/var/lib/acme-dns       \
+ -d joohoi/acme-dns
+```
+
+## Docker Compose
+
+1) Create directories: `config` for the configuration file, and `data` for the sqlite3 database.
+
+2) Copy [configuration template](https://raw.githubusercontent.com/joohoi/acme-dns/master/config.cfg) to `config/config.cfg` 
+
+3) Copy [docker-compose.yml from the project](https://raw.githubusercontent.com/joohoi/acme-dns/master/docker-compose.yml), or create your own.
+
+4) Edit the `config/config.cfg` and `docker-compose.yml` to suit your needs, and run `docker-compose up -d`
 
 ## Configuration
 
diff --git a/config.cfg b/config.cfg
index 77cd3f0..127daee 100644
--- a/config.cfg
+++ b/config.cfg
@@ -27,7 +27,8 @@ debug = false
 # Database engine to use, sqlite3 or postgres
 engine = "sqlite3"
 # Connection string, filename for sqlite3 and postgres://$username:$password@$host/$db_name for postgres
-connection = "acme-dns.db"
+# Please note that the default Docker image uses path /var/lib/acme-dns/acme-dns.db for sqlite3
+connection = "/var/lib/acme-dns/acme-dns.db"
 # connection = "postgres://user:password@localhost/acmedns_db"
 
 [api]
@@ -36,9 +37,9 @@ api_domain = ""
 # email to use for account registration for Let's Encrypt, used only if tls = "letsencrypt"
 le_email = "admin@example.com"
 # listen ip eg. 127.0.0.1
-ip = "127.0.0.1"
+ip = "0.0.0.0"
 # listen port, eg. 443 for default HTTPS
-port = "8080"
+port = "80"
 # possible values: "letsencrypt", "cert", "none"
 tls = "none"
 # only used if tls = "cert"
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..2c9ceea
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,14 @@
+version: '2'
+services:
+  acmedns:
+    build:
+      context: .
+      dockerfile: Dockerfile
+    image: joohoi/acme-dns:latest
+    ports:
+      - "443:443"
+      - "53:53"
+      - "80:80"
+    volumes:
+      - ./config:/etc/acme-dns:ro
+      - ./data:/var/lib/acme-dns
-- 
GitLab