Updating readme to cover lets encrypt

This commit is contained in:
Ric Harvey
2016-07-22 16:20:24 +01:00
parent e0b098f951
commit 4d56f79372

View File

@@ -1,5 +1,5 @@
## Introduction
This is a Dockerfile to build a container image for nginx and php-fpm, with the ability to pull website code from git. The container also has the ability to update templated files with vaiables passed to docker in order to update your settings.
This is a Dockerfile to build a container image for nginx and php-fpm, with the ability to pull website code from git. The container also has the ability to update templated files with variables passed to docker in order to update your settings. There is also support for lets encrypt SSL support.
### Git repository
The source files for this project can be found here: [https://github.com/ngineered/nginx-php-fpm](https://github.com/ngineered/nginx-php-fpm)
@@ -34,11 +34,23 @@ sudo docker run -d richarvey/nginx-php-fpm
```
You can then browse to ```http://<DOCKER_HOST>:8080``` to view the default install files. To find your ```DOCKER_HOST``` use the ```docker inspect``` to get the IP address.
### Volumes
If you want to link to your web site directory on the docker host to the container run:
```
sudo docker run -d -v /your_code_directory:/var/www/html richarvey/nginx-php-fpm
```
### Available Configuration Parameters
The following flags are a list of all the currently supported options that can be changed by passing in the variables to docker with the -e flag.
- **GIT_REPO** : URL to the repository containing your source code
- **GIT_BRANCH** : Select a specific branch (optional)
- **GIT_EMAIL** : Set your email for code pushing (required for git to work)
- **GIT_NAME** : Set your name for code pushing (required for git to work)
- **SSH_KEY** : Private SSH deploy key for your repository base64 encoded (requires write permissions for pushing)
- **WEBROOT** : Change the default webroot directory from `/var/www/html` to your own setting
- **ERRORS** : Set to 1 to display PHP Errors in the browser
- **TEMPLATE_NGINX_HTML** : Enable by setting to 1 search and replace templating to happen on your code
- **HIDE_NGINX_HEADERS** : Disable by setting to 0, default behaviour is to hide nginx + php version in headers
- **PHP_MEM_LIMIT** : Set higher PHP memory limit, default is 128 Mb
- **PHP_POST_MAX_SIZE** : Set a larger post_max_size, default is 100 Mb
- **PHP_UPLOAD_MAX_FILESIZE** : Set a larger upload_max_filesize, default is 100 Mb
- **DOMAIN** : Set domain name for Lets Encrypt scripts
### Dynamically Pulling code from git
One of the nice features of this container is its ability to pull code from a git repository with a couple of environmental variables passed at run time.
@@ -56,34 +68,40 @@ To run the container and pull code simply specify the GIT_REPO URL including *gi
```
sudo docker run -d -e 'GIT_REPO=git@git.ngd.io:ngineered/ngineered-website.git' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' richarvey/nginx-php-fpm
```
To pull a repository and specify a branch add the GIT_BRANCH environment variable:
```
sudo docker run -d -e 'GIT_REPO=git@git.ngd.io:ngineered/ngineered-website.git' -e 'GIT_BRANCH=stage' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' richarvey/nginx-php-fpm
```
### Enabling SSL or Special Nginx Configs
You can either map a local folder containing your configs to /etc/nginx or we recommend editing the files within __conf__ directory that are in the git repo, and then rebuilding the base image.
### Lets Encrypt support (Experimental)
#### Setup
You can use Lets Encrypt to secure your container. Make sure you start the container ```DOMAIN, GIT_EMAIL``` and ```WEBROOT``` variables to enable this to work. Then run:
```
sudo docker exec -t <CONTAINER_NAME> /usr/bin/letsencrypt-setup
```
Ensure your container is accessible on the ```DOMAIN``` you supply in order for this to work
#### Renewal
Lets Encrypt certs expire every 90 days, to renew simply run:
```
sudo docker exec -t <CONTAINER_NAME> /usr/bin/letsencrypt-renew
```
## Special Git Features
You'll need some extra ENV vars to enable this feature. These are ```GIT_EMAIL``` and ```GIT_NAME```. This allows git to be set up correctly and allow the following commands to work.
### Push code to Git
To push code changes made within the container back to git simply run:
```
sudo docker exec -t -i <CONTAINER_NAME> /usr/bin/push
```
### Pull code from Git (Refresh)
In order to refresh the code in a container and pull newer code form git simply run:
```
sudo docker exec -t -i <CONTAINER_NAME> /usr/bin/pull
```
### Templating
**NOTE: You now need to enable templates see below**
This container will automatically configure your web application if you template your code.
### Using environment variables
For example if you are using a MySQL server, and you have a config.php file where you need to set the MySQL details include $$_MYSQL_HOST_$$ style template tags.
@@ -110,32 +128,11 @@ MYSQL_HOST=host.x.y.z
MYSQL_USER=username
MYSQL_PASS=password
```
### Template anything
Yes ***ANYTHING***, any variable exposed by the **-e** flag lets you template your configuration files. This means you can add redis, mariaDB, memcache or anything you want to your application very easily.
## Logging and Errors
### Logging
All logs should now print out in stdout/stderr and are available via the docker logs command:
```
docker logs <CONTAINER_NAME>
```
## Available Configuration Parameters
The following flags are a list of all the currently supported options that can be changed by passing in the variables to docker with the -e flag.
- **GIT_REPO** : URL to the repository containing your source code
- **GIT_BRANCH** : Select a specific branch (optional)
- **GIT_EMAIL** : Set your email for code pushing (required for git to work)
- **GIT_NAME** : Set your name for code pushing (required for git to work)
- **SSH_KEY** : Private SSH deploy key for your repository base64 encoded (requires write permissions for pushing)
- **WEBROOT** : Change the default webroot directory from `/var/www/html` to your own setting
- **ERRORS** : Set to 1 to display PHP Errors in the browser
- **TEMPLATE_NGINX_HTML** : Enable by setting to 1 search and replace templating to happen on your code
- **HIDE_NGINX_HEADERS** : Disable by setting to 0, default behaviour is to hide nginx + php version in headers
- **PHP_MEM_LIMIT** : Set higher PHP memory limit, default is 128 Mb
- **PHP_POST_MAX_SIZE** : Set a larger post_max_size, default is 100 Mb
- **PHP_UPLOAD_MAX_FILESIZE** : Set a larger upload_max_filesize, default is 100 Mb
- **DOMAIN** : Set domain name for Lets Encrypt scripts