{ DreamFactory: 'Blog' }

Running DreamFactory as a Docker Container

Posted by Todd Appleton

Thu, Jun 11, 2015


Note: This blog post has been updated for DreamFactory 2.x.

DreamFactory can be run as a Docker container, which makes it easier than ever to get the backend for your apps up and running. The DreamFactory Docker image is available on Docker Hub, or you can build your own image from the GitHub repo. Using these two methods, I'll show you how to use Docker to fire up your own DreamFactory instance in just a few steps. The basic idea is that you first start a container for MySQL, then a container for DreamFactory which links to the MySQL container. 

Method 1: Using the Docker Hub Image

The DreamFactory image on Docker Hub is an automated build based on our df-docker repo on GitHub.  It's a basic DreamFactory install, meaning that it doesn't include drivers for some services like MS SQL or Oracle. If you need to customize your image with extra drivers all you need to do is clone the GitHub repo and build your own image that includes those extra drivers. See Method 2 below. Note that all the provided database credentials are defaults and you should change them.

Install Docker

See: https://docs.docker.com/linux/step_one/

Pull DreamFactory Image

docker pull dreamfactorysoftware/df-docker

Start the MySQL database container

docker run -d --name df-mysql -e "MYSQL_ROOT_PASSWORD=root" -e "MYSQL_DATABASE=dreamfactory" -e "MYSQL_USER=df_admin" -e "MYSQL_PASSWORD=df_admin" mysql

Start the DreamFactory container with linked MySQL database container

docker run -d -p -v /PATH_TO_ENV_FILE:/opt/dreamfactory/.env --link df-mysql:db dreamfactorysoftware/df-docker

Method 2: Build a Custom Image Using Docker CLI Commands

If you need something different than the image from Docker Hub you can build your own. Adding PHP drivers for other services is just a matter of editing the Dockerfile in your clone of the GitHub repo.

Install Docker

See: http://docs.docker.com/engine/installation/

Clone GitHub Repo

git clone https://github.com/dreamfactorysoftware/df-docker.git

Customize the Image

Edit the Dockerfile to customize the image. For example to add support for MS SQL, you would add the following to the 'apt-get-install' line in the Dockerfile. Other database types are supported by adding their respective drivers in a similar manner.

php5-sybase php5-odbc freetds-common

Build the DreamFactory Image

docker build -t dreamfactory/v2 .

Start the MySQL database container

docker run -d --name df-mysql -e "MYSQL_ROOT_PASSWORD=root" -e "MYSQL_DATABASE=dreamfactory" -e "MYSQL_USER=df_admin" -e "MYSQL_PASSWORD=df_admin" mysql

Start the DreamFactory container with linked MySQL database container

docker run -d -p -v /PATH_TO_ENV_FILE:/opt/dreamfactory/.env --link df-mysql:db dreamfactory/v2

There's another method to build your own image using Docker Compose which we won't detail here. Check out the README in the repo for more info on that.

Connect to your DreamFactory Admin Console

With the DreamFactory container running you can access your instance's admin console by going to http://localhost:80 in your browser. The first time you'll be asked to create an admin user for your iinstance. Use this email and password to login to the admin console. That's all there is to it. Now you're ready to start building apps using the REST API at, in this case, http://localhost:80/api/v2. From this point on you can use the Docker CLI commands to manage the containers.

Get started with DreamFactory with a free hosted DreamFactory development environment . Or, download and run it on the server, cloud, or desktop of your choice.


Weekly Digest