Setup Your Development Environment Based on Docker

Docker containers reduce the complexity of creating development environments. By using them, as a developer, you won’t have to care too much about server administration, e.g., MySQL, Redis or Apache, as it is largely handled by container orchestration.

In this guide, you will learn how to setup an ownCloud development environment, using Docker. To be able to do so, you need to follow these steps:

Prerequisite

This guide assumes that you already have docker and docker-compose installed on your computer. If you do not, download the version for your operating system and install it.

Get the Source

First, get the ownCloud source code, either by downloading a tarball or by cloning the source, and place it in a folder inside your home directory; for example: /home/<your-username>/src/owncloud.

Be aware that the ownCloud git repository contains a very raw version of ownCloud. It must be enriched with some other apps inside the owncloud/apps folder. It is possible to clone some different apps to that location. The user_management app for example.

Create the Development Environment with docker-compose

With the ownCloud source available, you can create a Docker-based development environment. To save time, we’ll use ownCloud’s docker-compose.yml file. It is designed to create a very simple production environment, so it requires some modifications.

See the Docker Compose file reference to learn all about the [docker-compose.yml] file format.

Download it to the root of the directory where you put the ownCloud source. After you download it, change the container image that is used within the ownCloud service to owncloudci/base:latest, as in the example below.

services:
  owncloud:
    image: owncloudci/base:latest

Next, the downloaded/cloned ownCloud source folder must be mounted into the container. To do so, add an entry to the volumes section, inside the ownCloud service configuration, as in the example below.

services:
  owncloud:
    image: owncloud/oc_dev:latest
    ...
    volumes:
      - <owncloud_source_directory>:/var/www/owncloud
      ... other volumes configuration

With those two changes made, start the Docker environment by running docker-compose up -d --build.

This does not install ownCloud, only starts the Docker container.
If this is your first time either running docker-compose up or using the owncloud/oc_dev container, it may take a few minutes to complete, as the container needs to be downloaded.

Build the Container

With the container running, ownCloud needs to be installed, by running the make command from inside the container. To do this, we first need to attach (log in) to the container. To do that, we need the running container’s name. You find that by running docker-compose ps, which will render output similar to that below in the console:

              Name                 Command               State                  Ports
-------------------------------------------------------------------------------------------------
oc_dev_docker_oc_dev_1           apache                  Up               80/tcp

Take note of the value in the Name column, i.e., oc_dev_docker_oc_dev_1. This string is a combination of three things, separated by underscores:

  1. The directory in which you ran docker-compose up (oc_dev_docker)

  2. The name of the container (oc_dev)

  3. The container’s auto-generated number (1)

To log in to the running container, replace <container_name> in the command below with the name of the container in the output from docker-compose ps.

docker-compose exec <container_name> /bin/bash

After logging in, run make. When the command completes, test that you can access ownCloud in your browser by opening http://localhost.

You can also use the occ command within the container, just as if you were on a production server.

Enable Debug Mode

Now that ownCloud’s available, we strongly encourage you to disable JavaScript and CSS caching during development. This ensures that changes immediately visible, not later, when the respective caches expire. To disable JavaScript and CSS caching, enable debug mode by setting debug to true in config/config.php, as in the example below.

<?php

$CONFIG = [
    'debug' => true,
    ... remaining configuration goes here ...
];

Do not enable this for production! This can create security problems and is only meant for debugging and development!

Setup ownCloud

With the steps completed, you’re now ready to use either the ownCloud installation wizard or the command line installer to finish setting up ownCloud.