Terence Bennett - May 19, 2018
large_h-dark

Note: We have updated the instructions here to match our DF-Docker repo instructions.  This will pull the latest GitHub repo now.

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.

Configuration method 1a (use docker-compose)

The easiest way to configure the DreamFactory application is to use docker-compose.

1) Clone the df-docker repo

cd ~/repos (or wherever you want the clone of the repo to be)
git clone https://github.com/dreamfactorysoftware/df-docker.git
cd df-docker

2) Edit docker-compose.yml (optional)

3) Build images

docker-compose build

4) Start containers

docker-compose up -d

NOTE: volume df-storage:/opt/dreamfactory/storage is created to store all file based (apps, logs etc.) data from DreamFactory.
This basically stores all data written by DreamFactory (at /opt/dreamfactory/storage location) in the df-storage volume. This 
way if you delete your DreamFactory container your data will persist as long as you don't delete the df-storage volume.

to stop and remove all containers you can use the command docker-compose down to stop and remove all containers including volumes use docker-compose down -v

5) Add an entry to /etc/hosts

127.0.0.1 dreamfactory.app

6) Access the app

Go to 127.0.0.1 in your browser. It will take some time the first time. You will be asked to create your first admin user.

Configuration method 2 (build your own)

If you don’t want to use docker-compose you can build the images yourself.

1) Clone the df-docker repo

cd ~/repos (or wherever you want the clone of the repo to be)

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

2) Build dreamfactory/v2 image

docker build -t dreamfactory .

3) Ensure that the database container is created and running

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

4) Ensure that the redis container is created and running

docker run -d --name df-redis redis

5) Start the dreamfactorysoftware/df-docker container with linked MySQL and Redis server

If your database and redis runs inside another container you can simply link it under the name db and rd respectively.

docker run -d --name df-web -p 80:80 -e "DB_DRIVER=mysql" -e "DB_HOST=db" -e "DB_USERNAME=df_admin" -e "DB_PASSWORD=df_admin" -e "DB_DATABASE=dreamfactory" -e "CACHE_DRIVER=redis" -e "CACHE_HOST=rd" -e "CACHE_DATABASE=0" -e "CACHE_PORT=6379" --link df-mysql:db --link df-redis:rd dreamfactory

6) Add an entry to /etc/hosts

127.0.0.1 dreamfactory.app

7) Access the app

Go to 127.0.0.1 in your browser. It will take some time the first time. You will be asked to create your first admin user.

 Notes

  • You may have to use
    sudo

    for Docker commands depending on your setup.

  • By default, the container only sends nginx error logs to STDOUT. If you also want to have dreamfactory.log, e.g. for forwarding via docker logging driver you can set environment variable
    LOG_TO_STDOUT=true

With the DreamFactory container running you can access your instance’s admin console by going to https://127.0.0.1 in your browser. The first time you’ll be asked to create an admin user for your instance. 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, https://127.0.0.1/api/v2. From this point on you can use the Docker CLI commands to manage the containers.