Make the user experience nicer
[discourse_docker.git] / README.md
CommitLineData
408a9c19
SS
1### About
2
8200fe05
JA
3- [Docker](https://www.docker.io/) is an open source project to pack, ship and run any Linux application in a lighter weight, faster container than a traditional virtual machine.
4
5- Docker makes it much easier to deploy [a Discourse forum](https://github.com/discourse/discourse) on your servers and keep it updated. For background, see [Sam's blog post](http://samsaffron.com/archive/2013/11/07/discourse-in-a-docker-container).
2619d8e3 6
faa6f226 7- The templates and base image configure Discourse with the Discourse team's recommended optimal defaults.
408a9c19 8
2a438fb6 9
4792b7d0 10### IMPORTANT: Before You Start
2a438fb6 11
259189ae 121. Make sure you're running a **64 bit** version of either [Ubuntu 12.04 LTS](http://releases.ubuntu.com/precise/), [Ubuntu 13.04](http://releases.ubuntu.com/13.04/) or [Ubuntu 13.10](http://releases.ubuntu.com/13.10/).
95c811d2
RH
132. Upgrade to the [latest version of Docker](http://docs.docker.io/en/latest/installation/ubuntulinux/).
143. Run Docker and launcher as **root**.
837466ae
JA
154. Install Discourse Docker into the expected path `/var/docker`
16
57867ae2 17If you do not do any of the above, as RoboCop once said, ["there will be ... trouble."](http://www.youtube.com/watch?v=XxarhampSNI) *Please double check the above list before proceeding!*
2a438fb6 18
4792b7d0 19### Getting Started
cd0f828e 20
8200fe05 21The simplest way to get started is the **standalone** template:
cd0f828e 22
2a438fb6 231. **Clone** this project from github: `git clone https://github.com/SamSaffron/discourse_docker.git /var/docker`
18d0278e
RH
242. **Copy** the standalone sample into the containers directory: `cp samples/standalone.yml containers/app.yml`
253. **Edit** `containers/app.yml` with your environment specific information
58584176 26 - [bindings](#expose)
851af3a4 27 - [volumes](#volumes) (make sure you create the appropriate directories on the host)
18d0278e
RH
284. **Bootstrap** the image: `sudo ./launcher bootstrap app`
295. **Start** the image: `sudo ./launcher start app`
cd0f828e 30
4792b7d0 31Note: you can add yourself to the Docker group if you wish to avoid `sudo` with `usermod -aG docker <your-user-name>`.
cd0f828e 32
408a9c19
SS
33### Directory Structure
34
8200fe05 35#### `/cids`
408a9c19
SS
36
37Contains container ids for currently running Docker containers. cids are Docker's "equivalent" of pids. Each container will have a unique git like hash.
38
8200fe05 39#### `/containers`
408a9c19 40
4792b7d0 41This directory is for container definitions for your various Discourse containers. You are in charge of this directory, it ships empty.
408a9c19 42
8200fe05 43#### `/samples`
408a9c19
SS
44
45Sample container definitions you may use to bootstrap your environment. You can copy and amend templates here into the containers directory.
46
8200fe05 47#### `/shared`
408a9c19
SS
48
49Placeholder spot for shared volumes with various Discourse containers. You may elect to store certain persistent information outside of a container, in our case we keep various logfiles and upload directory outside. This allows you to rebuild containers easily without losing important information. Keeping uploads outside of the container allows you to share them between multiple web instances.
50
8200fe05 51#### `/templates`
408a9c19
SS
52
53[pups](https://github.com/samsaffron/pups) managed pups templates you may use to bootstrap your environment.
54
8200fe05 55#### `/image`
408a9c19
SS
56
57Dockerfile for both the base image `samsaffron/discoruse_base` and discourse image `samsaffron/discourse`.
58
faa6f226 59- `samsaffron/discourse_base` contains all the OS dependencies including sshd, runit, postgres, nginx, ruby.
408a9c19 60
faa6f226 61- `samsaffron/discourse` builds on the base image and configures a discourse user and `/var/www/discourse` directory for the Discourse source.
408a9c19
SS
62
63The Docker repository will always contain the latest built version at: https://index.docker.io/u/samsaffron/discourse/ , you should not need to build the base image.
64
58584176 65### Launcher
408a9c19
SS
66
67The base directory contains a single bash script which is used to manage containers. You can use it to "bootstrap" a new container, ssh in, start, stop and destroy a container.
68
69```
70Usage: launcher COMMAND CONFIG
71Commands:
72 start: Start/initialize a container
73 stop: Stop a running container
74 restart: Restart a container
75 destroy: Stop and remove a container
76 ssh: Start a bash shell in a running container
77 logs: Docker logs for container
78 bootstrap: Bootstrap a container for the config based on a template
79```
80
408a9c19 81
4792b7d0 82### Container Configuration
408a9c19 83
faa6f226 84The beginning of the container definition will contain 3 "special" sections:
408a9c19 85
58584176 86#### templates:
408a9c19
SS
87
88```
89templates:
90 - "templates/cron.template.yml"
91 - "templates/postgres.template.yml"
92```
93
faa6f226 94This template is "composed" out of all these child templates, this allows for a very flexible configuration struture. Furthermore you may add specific hooks that extend the templates you reference.
408a9c19 95
58584176 96#### expose:
408a9c19
SS
97
98```
99expose:
100 - "2222:22"
101```
102
103Expose port 22 inside the container on port 2222 on ALL local host interfaces.
104
105
58584176 106#### volumes:
408a9c19
SS
107
108```
109volumes:
110 - volume:
111 host: /var/docker/data
112 guest: /shared
113
114```
115
116Expose a directory inside the host inside the container.
117
4792b7d0 118### Upgrading Discourse
c57d9880 119
4792b7d0 120The Docker setup gives you multiple upgrade options:
c57d9880 121
4792b7d0 1221. Use the front end at http://yoursite.com/admin/docker to upgrade an already running image.
c57d9880 123
4792b7d0 1242. Create a new base image by running:
c57d9880
SS
125 - `./launcher bootstrap my_image`
126 - `./launcher destroy my_image`
127 - `./launcher start my_image`
128
4792b7d0 129### Single Container vs. Multiple Container
c57d9880 130
4792b7d0 131The samples directory contains a standalone template. This template bundles all of the software required to run Discourse into a single container. The advantage is that it is easy.
c57d9880 132
4792b7d0 133The multiple container configuration setup is far more flexible and robust, however it is also more complicated to set up. A multiple container setup allows you to:
c57d9880 134
6776444f 135- Minimize downtime when upgrading to new versions of Discourse. You can bootstrap new web processes while your site is running and only after it is built, switch the new image in.
4792b7d0
JA
136- Scale your forum to multiple servers.
137- Add servers for redundancy.
138- Have some required services (e.g. the database) run on beefier hardware.
6776444f
JA
139
140If you want a multiple container setup, see the `data.yml` and `web_only.yml` templates in the samples directory. To ease this process, `launcher` will inject an env var called `DISCOURSE_HOST_IP` which will be available inside the image.
c57d9880 141
4792b7d0 142WARNING: In a multiple container configuration, *make sure* you setup iptables or some other firewall to protect various ports (for postgres/redis).
58584176 143
4792b7d0 144### Email
2e2e7049 145
4792b7d0 146For a Discourse instance to function properly Email must be set up. Use the `SMTP_URL` env var to set your SMTP address, see sample templates for an example. The Docker image does not contain postfix, exim or another MTA, it was omitted because it is very tricky to set up correctly.
2e2e7049 147
58584176 148### Troubleshooting
c57d9880 149
4792b7d0 150We strongly recommend you have ssh access to your running containers, this allows you very easily take a sneak peek at internals. The simplest way to gain access is:
c57d9880
SS
151
1521. Run a terminal as root
1532. cd `~/.ssh`
1543. `ssh-key-gen`
1554. paste the contents of `id_rsa.pub` into your templates (see placeholder in samples)
1565. bootstrap and run your container
1576. `./launcher ssh my_container`
158
58584176 159### Security
c57d9880 160
4792b7d0 161Directory permissions in Linux are SID based, if your SIDs on the host do not match the SIDs in the guest, permissions will mismatch. On clean installs you can ensure they are in sync by looking at `/etc/passwd` and `/etc/group`, the Discourse account will have the SID 1000.