electerious/Lychee — pull request #252 by renfredxh (2014-10-26 20:08:21+00:00)
Title: Docker Improvements

This PR includes all of the remaining improvements for Docker requested in #237. This includes:

- **Install ImageMagick**
- ImageMagick is now installed during the `RUN` command for installing dependences. I wasn't sure of a way to test and see if Lychee was actually using it, but I'm assuming that if it's installed and enabled in Lychee's settings it will work.
- **Updated values in `php.ini`**
- A [`RUN` command](https://github.com/renfredxh/Lychee/blob/87127da99f46dbd9dbde65117f6178d0dad9014a/Dockerfile#L11-L20) now configures settings in php.ini to the recommended values.
- **Use data volumes**
- I figured out everything that was necessary to launch the application and maintain persistent data using volumes (see below).

As requested, here are the instructions for installing Lychee using Docker. Feel free to include any parts of this throughout Lychee's documentation where appropriate.

## Installation Using Docker

*Note: pre-installation of the latest version of [Git](http://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and [Docker](https://docs.docker.com/installation/) is required to deploy Lychee using Docker.*

First, you should clone the latest version of Lychee and build it using the Dockerfile included in the repository.

```bash
git clone https://github.com/electerious/Lychee.git
cd Lychee
sudo docker build -t lychee .
```
Once this is finished, remember to set the proper permissions on the `uploads` and `data` directories so the container can mount these directories as volumes.
```
chmod -R 777 uploads/ data/
```
Now you can use the `docker run` command to run your Lychee container.
```bash
sudo docker run -v /var/lib/mysql --name lychee_data \
-v $(pwd)/data:/app/data \
-v $(pwd)/uploads:/app/uploads \
-i -t -d -p 8000:80 lychee
```
Browse to [localhost:8000](http://localhost:8000/) (the port can be specified via the `-p` flag) and you will see Lychee's configuration page. The default database username is `root` with no password (you can manage MySQL users by running `docker exec -i -t mysql`). After submitting your database configuration, you can sign in and create a new username and password and start using Lychee.

*Note: if you are deploying on a server, you might want to forward your container to port `80` instead of `8000` so it'll be publicly accessible.*

### Managing Data
Running the container with the above options mounts three Docker [data volumes](https://docs.docker.com/userguide/dockervolumes/). The first is a named data volume used to store the MySQL database. The last two will mount the `/data` and `/uploads` from the container to your host `Lychee` directory. If you would like to upgrade or redeploy Lychee while preserving your data, you can kill the container and the volumes will persist. Just rebuild your new container and run it using a similar command:

```bash
sudo docker run --volumes-from lychee_data \
-v $(pwd)/data:/app/data \
-v $(pwd)/uploads:/app/uploads \
-i -t -d -p 8000:80 lychee
```