{ DreamFactory: 'Blog' }

Running DreamFactory as a Docker Container

Posted by Todd Appleton

Thu, Jun 11, 2015

large_h-dark 

Note: This blog post has been updated for DreamFactory 2.x, and now shows how to use Redis for cache.

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. This setup uses MySQL for the system database and Redis for the system cache. The basic idea is that you first start the containers for MySQL and Redis, then a container for DreamFactory which links to the others. 

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 Redis container

docker run -d --name df-redis redis

Start the DreamFactory container with linked MySQL and Redis

docker run -d --name df-web -p 127.0.0.1:80 -e "DB_HOST=db" -e "DB_USERNAME=df_admin" -e "DB_PASSWORD=df_admin" -e "DB_DATABASE=dreamfactory" -e "REDIS_HOST=rd" -e "REDIS_DATABASE=0" -e "REDIS_PORT=6379" --link df-mysql:db --link df-redis:rd 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

You can optionally edit the Dockerfile to customize the image. For example you might use apt-get to add support for other service types.

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 Redis container

docker run -d --name df-redis redis

Start the DreamFactory container with linked MySQL and Redis

docker run -d --name df-web -p 127.0.0.1:80:80 -e "DB_HOST=db" -e "DB_USERNAME=df_admin" -e "DB_PASSWORD=df_admin" -e "DB_DATABASE=dreamfactory" -e "REDIS_HOST=rd" -e "REDIS_DATABASE=0" -e "REDIS_PORT=6379" --link df-mysql:db --link df-redis:rd 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.

Docker

Weekly Digest