How to use Nginx as reverse proxy with Docker
I have already write some articles about EasyEngine, and I'm really in love with this command line tool, because it make Nginx easier to use than Apache. But I haven't talk about all functionality of EE yet. If it provide you the ability to setup a WordPress website easily, you can also use EasyEngine to create a vhost for a static html website ... Or use Nginx as a reverse proxy !
And that make of EE the most complete tool available to use Nginx without having to read thousands of documentation pages to understand how to create a vhost. But don't worry, this article will not only talk about this awesome tool which is EasyEngine.
I have used docker several times in the past, because it's the fastest way to test an application without having to setup a VPS especially for that. But to run several Docker containers in a single VPS, it could quickly be a problem because some container provide you the ability to use a domain like WordPress for example. And some other will use directly your VPS IP and the port of your choice, which is not very friendly when your app is running on http://192.168.0.1:3000 ...
That's why we will use Nginx to act as a reverse proxy for our Docker containers, and we will be able to run several containers on the same server and to access them with the domain of our choice. So the first step is to install Docker. Don't worry you should not need to read the documentation if you are using a VPS with a recent linux distribution and a kernel 3.13+
### install Docker with a single command on debian/ubuntu/centos
wget -qO- https://get.docker.com/ | sh
Docker is now running on your server ! So let's install EasyEngine :
## Install EasyEngine Debian7/8 or Ubuntu 14.04/16.04 LTS
wget -qO ee rt.cx/ee && bash ee
So we have now Docker and EasyEngine installed and we can launch our first Docker App before routing it with Nginx.
We will start with Rocket.Chat, a complete live chat solution to build a community or to provide live support.
## Launch MongoDB container
docker run --name db -d mongo:3.0 --smallfiles
## Run Rocket.Chat linked to the db and expose port 3000
docker run --name rocketchat -p 3000:3000 --env ROOT_URL=http://localhost --link db -d rocket.chat
So you should be able to access to Rocket.Chat using http://YOUR-VPS-IP:3000.
And to use Nginx as reverse proxy with your domain :
ee site create yourdomain.com --proxy=127.0.0.1:3000
That's it ! You can now use http://yourdomain.com to access to Rocket.Chat
Some other apps to run with Nginx as reverse proxy :
## Hastebin
docker run --name redis -d redis
docker run --name hastebin -d -p 7777:7777 --link redis:redis -e STORAGE_HOST=redis rlister/hastebin
## Pasteboard
docker run --name pasteboard -e ORIGIN=mydomain.tld -e MAX=7 -v /srv/pasteboard/images:/pasteboard/public/storage -p 4000:4000 anthodingo/docker-pasteboard