Install tsuru and Docker

This document describes how to manually install all tsuru compoments in one virtual machine. Installing all components in one machine is not recommended for production ready but is a good start to have a tsuru stack working.

You can install it automatically using tsuru-now (or tsuru-bootstrap, that runs tsuru-now on vagrant).

tsuru components are composed by:

  • MongoDB
  • Redis
  • Hipache
  • Docker
  • Gandalf
  • tsuru API

This document assumes that tsuru is being installed on a Ubuntu Server 14.04 LTS 64-bit machine.

Before install

Before install, let’s install curl and python-software-properties, that are used to install extra repositories.

sudo apt-get update
sudo apt-get install curl python-software-properties -qqy

Adding repositories

Let’s start adding the repositories for Docker, tsuru and MongoDB.

sudo apt-key adv --keyserver hkp:// --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
echo "deb docker main" | sudo tee /etc/apt/sources.list.d/docker.list

sudo apt-key adv --keyserver hkp:// --recv 7F0CEB10
echo "deb dist 10gen" | sudo tee /etc/apt/sources.list.d/mongodb.list

sudo apt-add-repository ppa:tsuru/ppa -y

sudo apt-get update

Installing MongoDB

tsuru uses MongoDB to store all data about apps, users and teams. Let’s install it:

sudo apt-get install mongodb-org -qqy

Installing Redis

tsuru uses Redis for message queueing and Hipache uses it for storing routing data.

sudo apt-get install redis-server -qqy

Installing Hipache

Hipache is a distributed HTTP and websocket proxy. tsuru uses Hipache to route the requests to the containers.

In order to install Hipache, just use apt-get:

sudo apt-get install node-hipache -qqy

Now let’s start Hipache

sudo start hipache

Installing docker

sudo apt-get install lxc-docker -qqy

tsuru uses the docker HTTP api to manage the containers, to it works it is needed to configure docker to use tcp protocol.

To change it, edit the /etc/default/docker adding this line:

export DOCKER_OPTS="-H"

Then restart docker:

sudo stop docker
sudo start docker

Installing gandalf and archive-server

tsuru uses gandalf to manage git repositories.

sudo apt-get install gandalf-server -qqy

A deploy is executed in the git push. In order to get it working, you will need to add a pre-receive hook. Tsuru comes with three pre-receive hooks, all of them need further configuration:

In this tutorial, we will use archive-server, but you can use anything that can store a git archive and serve it via HTTP or FTP. You can install archive-server via apt-get too:

sudo apt-get install archive-server -qqy

Then you will need to configure Gandalf, install the pre-receive hook, set the proper environment variables and start Gandalf and the archive-server:

sudo mkdir -p $hook_dir
sudo curl -o ${hook_dir}/pre-receive
sudo chmod +x ${hook_dir}/pre-receive
sudo chown -R git:git /home/git/bare-template
cat | sudo tee -a /home/git/.bash_profile <<EOF

In the /etc/gandalf.conf file, remove the comment from the line “template: /home/git/bare-template”, so it looks like that:

    location: /var/lib/gandalf/repositories
    template: /home/git/bare-template

Then start gandalf and archive-server:

sudo start gandalf-server
sudo start archive-server

Installing tsuru API server

sudo apt-get install tsuru-server -qqy

sudo sed -i -e 's/=no/=yes/' /etc/default/tsuru-server
sudo start tsuru-ssh-agent
sudo start tsuru-server-api

Now you need to customize the configuration in the /etc/tsuru/tsuru.conf.

sudo vim /etc/tsuru/tsuru.conf

The basic configuration is:

listen: ""
debug: true
host: http://machine-public-ip:8080 # This port must be the same as in the "listen" conf
admin-team: admin
    user-registration: true
    scheme: native # you can use oauth or native
    name: tsurudb
queue: redis
    port: 6379

Now we will configure git:

    unit-repo: /home/application/current

Finally, we will configure docker:

provisioner: docker
    segregate: false
    router: hipache
    collection: docker_containers
    repository-namespace: tsuru
    deploy-cmd: /var/lib/tsuru/deploy
    ssh-agent-port: 4545
        redis-prefix: docker-cluster
        bin: /var/lib/tsuru/start
        port: "8888"
        add-key-cmd: /var/lib/tsuru/add-key
        public-key: /var/lib/tsuru/.ssh/
        user: ubuntu
    domain: # tsuru uses this to mount the app's urls

All confs are better explained here.

Generating token for Gandalf authentication

The last step before is to tell the pre-receive script where to find the tsuru server and how to talk to it. We do that by exporting two environment variables in the ~git/.bash_profile file:

cat | sudo tee -a /home/git/.bash_profile <<EOF
export TSURU_HOST=
export TSURU_TOKEN=`tsr token`

Using tsuru client

Congratulations! At this point you should have a working tsuru server running on your machine, follow the tsuru client usage guide to start build your apps.

Installing platforms

After creating the first user and the admin team, you can use the tsuru-admin to install your preferred platform:

tsuru-admin platform-add platform-name --dockerfile dockerfile-url

For example, Python:

tsuru-admin platform-add python --dockerfile

You can see the oficial tsuru dockerfiles here:

Here you can see more docs about tsuru-admin.

Adding Services

Here you will find a complete step-by-step example of how to install a mysql service with tsuru: Install and configure a MySQL service.

DNS server

You can integrate any DNS server with tsuru. Here you can find an example of using bind as a DNS forwarder, integrated with tsuru.