Home

Awesome

ownCloud

In the Cloud9 example, we learned how to define persisted volumes in the NDS Labs service spec. Now let's try a realistic example using some services we would like to eventually see in NDS Labs: owncloud and mysql.

In this example we will introduce specifying dependencies between services, and how to define environment variables to handle custom configuration.

Docker Image

Since this example uses official images, there is nothing to build.

But what if the image will not work with NDS Labs out of the box and requires slight customization?

There are 2 options readily available if we want to customize an existing Docker image.

Option 1: Create a Dockerfile from a Base Image

Create a Dockerfile that starts with FROM owncloud:latest. You can then make any additions or customizations that we would like, build a new image from this Dockerfile, and push it to Docker Hub.

We have provided an example of such a Dockerfile.

You can build this image by running the following command:

docker build -t owncloud .

Option 2: Run, Modify, and Commit

Jump into a running container using docker exec -it <container name or id> /bin/bash to modify a running container in-place.

You can then use:

Pushing to Docker Hub

If you have created a Docker Hub account, you can push this image up there for NDS Labs to pull down.

docker tag owncloud USERNAME/owncloud
docker login
docker push USERNAME/owncloud

NOTE: If you have already successfully executed docker login on this machine, you will not need to log in again.

NDS Labs Spec

Now that we have a Docker image for our service, we need to tell NDS Labs how to run this image.

For this, we will need to wrap it in a JSON service spec.

The following spec defines how NDS Labs will use the "owncloud" image:

{
  "key": "owncloud",
  "label": "ownCloud",
  "image": "USERNAME/owncloud:latest",
  "description": "A self-hosted file sync and share server",
  "access": "external",
  "display": "stack",
  "depends": [
    { "key": "mysql", "required": false }
  ],
  "ports": [
    { "port": 80, "protocol": "http" }
  ],
  "volumeMounts": [
    { "name": "owncloud", "mountPath": "/var/www/owncloud" }
  ]
}

NOTE: If you don't have a USERNAME from Docker Hub, simply use ndslabs in place of USERNAME above to pull down and run our pre-built example image.

Dependencies

You might have noticed the depends section in the spec above: this defines a "service dependency".

Dependencies can be either required or optional.

The following spec defines how NDS Labs will use the optional "mysql" dependency:

{
    "key": "mysql",
    "label": "MySQL",
    "image": "mysql:latest",
    "description": "An open-source relational database management system",
    "access": "internal",
    "display": "standalone",
    "config": [
      { "name": "MYSQL_ROOT_PASSWORD", "value": "",         "label": "Root Password", "canOverride": false, "isPassword": true  },
      { "name": "MYSQL_DATABASE",      "value": "owncloud", "label": "Database",      "canOverride": false, "isPassword": false },
      { "name": "MYSQL_USER",          "value": "username", "label": "Username",      "canOverride": true,  "isPassword": false },
      { "name": "MYSQL_PASSWORD",      "value": "",         "label": "Password",      "canOverride": true,  "isPassword": true  }
    ],
    "ports": [
        { "port": 3306, "protocol": "tcp" }
    ],
    "volumeMounts": [
      { "name": "mysql", "mountPath": "/var/lib/mysql" }
    ]
}

Environment Variables

The above spec includes another new section: config, which contains an array of configuration options. This allows you to specify environment variables, as well as their default values, that should be passed in when running the image.

You can specify the following to customize your configuration options:

Loading ownCloud and MySQL into NDS Labs

Run the following command from the system-shell to load this custom spec into NDS Labs:

ndslabsctl add service -f mysql.json
ndslabsctl add service -f owncloud.json

You will be prompted for the admin password (default: "admin") in order to add a service.

Reloading the UI will show your new service(s) listed and ready to add from the left-side pane.

Testing ownCloud

Now that we have our owncloud spec loaded, let's try to create an instance of it in NDS Labs!

  1. If you're not already running your own instance of NDS Labs, check out our Setup Documentation.
  2. Navigate your browser to http://YOUR_IP:30000 (create a project if necessary) and log in.
  3. You should now see "ownCloud" listed with the other services on the left side of the page.
  4. Click the + button beside "ownCloud" and step through the wizard to configure ownCloud:
  1. Click the name of the stack to expand the accordion and show a more fine-grained status.
  2. Click the "Launch Stack" button at the bottom-right of the pane.
  3. Wait for the stack to start.
  1. Once the stack has started, navigate to its endpoint by click the link to the right of the service name.
  2. A new tab will open, where you will be taken to the ownCloud self-installation web interface.
  1. You should then be brought to your ownCloud instance's home page, where you will be able to upload new files and view existing files existing on the attached volume.
  2. Upload a test file somewhere into ownCloud using the + button at the top-left of the screen.

Testing ownCloud + MySQL

We've tested our ownCloud spec, but what about the MySQL integration?

  1. If you're not already running your own instance of NDS Labs, check out our Setup Documentation.
  2. Navigate your browser to http://YOUR_IP:30000 (create a project if necessary) and log in.
  3. You should now see "ownCloud" listed with the other services on the left side of the page.
  4. Click the + button beside "ownCloud" and step through the wizard to configure ownCloud:
  1. Click the name of the stack to expand the accordion and show a more fine-grained status.
  1. Click the "Launch Stack" button at the bottom-right of the pane.
  2. Wait for the stack to start.
  1. Once the stack has started, navigate to its endpoint by click the link to the right of the service name.
  2. A new tab will open, where you will be taken to the ownCloud self-installation web interface.
  1. You should then be brought to your ownCloud instance's home page, where you will be able to upload new files and view existing files existing on the attached volume.
  2. Upload a test file somewhere into ownCloud using the + button at the top-left of the screen.
  3. To verify that MySQL is receiving updates from ownCloud, let's find a reference to the file you just uploaded in the MySQL database.

Success!

Congratulations! You made it through the entire tutorial.

You should now have everything you need to start authoring your own images and services specs to add to NDS Labs.