Running Phabricator with Docker, Docker-Machine, Amazon, and Nginx

Recently I began using Phabricator to help client’s track their code bases, and being a born-again (and therefore fervent) docker user, I wanted to use docker containers to deploy phabricator for all of my clients.

Step 1: Install Docker and Docker-Machine

Docker consists of 2 parts — the “Docker Engine” and the “Docker Machine”. The Docker Engine is run at a terminal using the “docker” command, and is used to deploy docker containers onto a machine. A “Docker Machine” is any server or computer running the Docker Engine.

Docker-Machine and the `docker-machine` command line tool allow you to set up new servers running the docker engine and manage those easily.

Both can be installed for your platform by installing the docker toolbelt from the following link:

You’ll only need to install the docker toolbelt on your local development machine for now. Docker-Machine will take care of installing the docker engine everywhere else.

Step 2: Create a docker machine on Amazon AWS

Once you’ve install the docker toolbelt, you can provision a new server on Amazon directly from the docker-machine command line program.

You’ll need to have an Amazon AWS account already and the ability to create new docker machines on AWS. To create a new machine, use the docker-machine command and specify the amazonec2 driver:

Make sure your region is supported. For a list of supported regions, check out the aws driver documentation:

Step 3: Switch your environment to your new Docker machine.

Now that you have docker-machine running and configured, it’s time to run the phabricator docker container on your server.

docker-machine allows you to switch between multiple machines easily. It does this by configuring your “docker” command to run in a specific “environment”, where “environment” represents your current docker machine. To run commands on a machine, you must switch to the environment for that machine using the ‘docker-machine env’ command.

Where is the name of the machine you created above.

This will output a shell script that you can run to set up the environment for that machine. It looks something like the following:

This command hasn’t done any environment switching yet — it just prints out the commands that it will execute to change the environment. To actually change the environment, run the last line in the comments without the #

Your environment will now be switched, and all docker commands will run on the docker-machine you just specified.

Step 4: Run the Phabricator-Mysql Docker container to your new Docker machine

Docker best practices include using a “volume container” to store your data that’s separate from the container your application is running in. The “volume container” is just a separate docker container running the MySQL database.

We’ll run the mysql container first so the phabricator container has something to attach to. I’ll use an already existing container from user yesnault:

Run the following command to create a new mysql docker container in your new environment:

In this case, the name “phabDB” will be used to connect our upcoming phabricator container to this datbabase container. You can name this whatever you want, as long as it’s constent with the next step.

Step 5: Run the Phabricator Docker container on your new Docker Machine

Once you have the MySQL container running, you can run the phabricator container using the following command:

This command tells docker to run an instance of the docker-phabricator container and name it “phab”. Phab is linked to the above phabDB container (inside the “phab” container the “phabDB” container is referred to as “database”). Finally, we’ll map port 80 on the container to port 8081 of your server so that all web calls from the phab container can be accessed by your server on port 8081.

Step 6: Install and Configure NGINX as a Reverse-proxy

We want to abstract the container from the outside world for various reasons, including security and load balancing purposes. Here we’ll use nginx configured as a reverse proxy to allow us to connect to our server on port 80 and have it connect to the phabricator contianer.

First, log into your server using the docker-machine command:

This will allow you to log into the server running the docker engines with Phab and PhabDB.

Next, we’ll install nginx. By default the docker-machine creates an Ubuntu-based machine, so we’ll use apt-get to install nginx.

Once that’s installed, we’ll go into the “sites-available” section of the nginx configuration directory and create a new configuration file:

Now, open the newly created “phabricator” file using a text editor (nano, vim, etc) and add the following configuration:

This will configure nginx to pass the headers of the connection to your server along to the webserver running in the “phab” container. Note the proxy_pass location — that’s how the external server knows to send all commands to the phab container at port 8081. If you chose a different port mapping when you executed `docker run` then you’ll need to change the port number there.

Step 7: Modify your Security Group to Allow HTTP Port Access

The last step is to add the HTTP ports to your docker-machine running on Amazon AWS. The default Amazon AWS image used by docker-machine doesn’t have these ports available, so we’ll add them directly in the AWS console.

  1. Navigate to and log in with your credentials.
  2. Find the EC2 machine running your docker containers. If you don’t see your machine running there, check the region in the upper right corner of the console to ensure that you’re in the correct region.
  3. In the navigation menu of the console on the left side of the screen, click on the “Security Groups” section under “Network & Security
  4. Right-click on the group with the name “docker-machine” and click “Edit Inbound Rules
  5. Click on the “Add Rule” button on the bottom of the dialog, and select “HTTP” from the drop-down.
  6. Optionally, you can click “Add Rule” again and add “HTTPS” from the drop down as well.
  7. Optionally, you can click “Add Rule” again and add “SMTP” to send emails from Phabricator

Step 8: Navigate to your EC2 instance and configure Phabricator

Navigate to the IP address or domain name of your EC2 instance in a web browser. You should see instructions for setting up Phabricator inside of the Phabricator instance.

Written by

Entrepreneur. Engineer. Educator.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store