Table of Contents

KnowRob & Docker -- developer documentation

This page lists information for developers that would like to modify, update and develop the docker images. If you would only like to start the existing docker containers, please have a look here.

Building Docker images

The Dockerfiles for the KnowRob containers can be found in this repository: https://github.com/knowrob/docker. You can build docker images from them using

cd ~/docker/hydro-knowrob/hydro-knowrob-base
docker build -t knowrob/hydro-knowrob-base .
 
cd ~/docker/hydro-knowrob/hydro-knowrob-daemon
docker build -t knowrob/hydro-knowrob-daemon .
 
cd ~/docker/hydro-knowrob/hydro-knowrob-interactive
docker build -t knowrob/hydro-knowrob-interactive .
 
cd ~/docker/webapps/easeapp
docker build -t openease/easeapp .
 
cd ~/docker/webapps/login
docker build -t openease/login .
 
cd ~/docker/webapps/knowrob
docker build -t openease/knowrob .

You can tag a version of an image using

docker tag 18df3323a0d8 openease/knowrob:0.1.0

Sharing images via Docker hub

Instead of building all images from Dockerfiles, you can also upload and download them from/to Docker hub. The push/pull interaction is very similar to git and uses the 'tags' associated with an image for describing which one to share:

  # upload image:
  docker push knowrob/hydro-knowrob-daemon
 
  # download images (this can also be done with the 'update-containers' script)
  docker pull knowrob/hydro-knowrob-daemon
  docker pull knowrob/knowrob_data
  docker pull knowrob/user_data
  docker pull openease/easeapp
  [...]

Running Docker containers

KnowRob containers

There are two versions of the KnowRob container: The interactive one starts a Bash shell that can be used for console-based interaction with the system. The other one is a daemonized version that starts KnowRob and json_prolog as a daemon without interactive shell.

  # interactive:
  docker run -t -P -i knowrob/hydro-knowrob-interactive /bin/bash
 
  # daemon mode:
  docker run -t -P -d knowrob/hydro-knowrob-daemon

MongoDB

  docker run -d -v /data/db --name mongo_data busybox true
  docker run -d -p 27017:27017 --volumes-from mongo_data --name mongo_db mongo

Importing data into MongoDB

If you want to import data into a dockerized MongoDB instance, first start an interactive container that mounts the host directory which contains the exported json files:

  docker run -t -P --rm --link mongo_db:mongo \
         -v /home/tenorth/work/roslog:/var/roslog \
         -i knowrob/hydro-knowrob-interactive /bin/bash

Then you can run the 'mongoimport' program from within the container. Make sure to set the host correctly, i.e. to refer to the MongoDB instance in the other container:

  cd /var/roslog/<experiment-id>
  mongoimport --host "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT" --db roslog --collection tf tf.json

Managing data using containers

Docker containers are cheap and usually short-lived, i.e. they can easily be started, stopped, removed and updated. The problem is how to store persistent data such as the content of a database or user-specific files. The approach we use are data-only containers – normal containers that contain nothing but a data volume that can be mounted by the other containers that provide the applications. These data-only containers shall not be removed, but can persist over longer time, also if the application containers get updated.

In the KnowRob use case, there is one container for user data (called user_data), and another one for common data (called knowrob_data). The user container will serve as sandbox in which users can store their files, the knowrob_data container will provide commonly used data sets. The common data container knowrob_data is auto-built on DockerHub from the knowrob_data GithHub repository.

Updating the common data container

The knowrob_data image is automatically built whenever new data is pushed to the knowrob_data GitHub repository. This image is, however, not automatically updated in the server's registry. In order to pull the newest version and to replace the running container with a new one, use the following commands:

  docker pull knowrob/knowrob_data:latest 
  docker rm knowrob_data
  docker run --name knowrob_data knowrob/knowrob_data:latest true

Starting a user container that includes the data volumes

If the KnowRob image has been built as described earlier, it can be started using the following command such that both the common and the user-specific data volumes are mounted:

  # interactive mode
  docker run -t -P -i --rm \
             --volumes-from knowrob_data \
             --volumes-from user_data \
             --name demo \
             --link mongo_db:mongo \
             knowrob/hydro-knowrob-interactive \
             /bin/bash
 
  # daemon mode
  docker run -t -P -d --rm\
             --volumes-from knowrob_data \
             --volumes-from user_data \
             --name demo \
             --link mongo_db:mongo \
             knowrob/hydro-knowrob-daemon
 

These examples are for the user 'demo', so 'demo' has to be replaced with the respective username.