Skip to main content Skip to Footer

BLOG


March 14, 2016
Docker Dependency using Mesosphere's Marathon Groups
By: Miguel Bernadin

Prior to docker compose, a docker container can be run as a standalone image and ports can be exposed on the host if that is required. This works if you have an independent application. However, many people would like to have applications that depend on each other and deployed together. This is where docker compose comes into play, but if you have a Mesos environment, where does that fit if you’re using a scheduler like Marathon? The closest thing we have to docker compose on Mesos is Marathon groups. You could also play with docker-compose-executor but I will leave that for another post. One ideal configuration is that your database container must start prior to your web frontend container. You will notice that I have 2 busybox docker containers representing the database and another 2 for the node-js application. I have mapped a dependency from my node-js app. You will notice that Marathon will not launch node-js app until my database is in a running state.

Here are three examples of the difference between docker-compose and Marathon groups:

  • With Marathon, you can specify the number of instances for each children, for example node-js-app.instance = 10; in docker-compose, you cannot do that. You can go ahead and scale it after 1 has been deployed.

  • With Docker-compose, the order of deployment is from top down. In Marathon, it is dependent on the dependencies field. (You can see this below in the json)

  • With Docker-compose, if you wanted to talk with an application your code references the container name and docker handles the rest. For Marathon, it would leverage Mesos-DNS (for example, myappid.frameworkname.mesos ). Be careful for statically naming your hostnames without the ability to change it. You may want to give yourself the ability to have your containers run in many types of environments. This is a perfect opportunity to leverage environment variables.

I have named my json group.json:

{
      "id": "node-js-app",
      "apps":[
            {
              "container": {
                "type": "DOCKER",
                "docker": {
                  "image": "busybox",
                  "privileged": true,
                  "network": "BRIDGE",
                  "parameters": [
                      { "key": "tty", "value": "true" }
                  ],
                  "portMappings": [
                            {
                                "containerPort": 80,
                                "hostPort": 0,
                                "protocol": "tcp"
                            }
                        ]
                },
                "volumes": [
                        {
                                "containerPath": "/var/www",
                                "hostPath": "/tmp",
                                "mode": "RW"
                        }
                ]
              },
              "id": "my-node-js-app",
              "instances": 2,
              "dependencies": ["/product/database"],
              "cpus": 1,
              "mem": 256
            }
      ]
   },
  {
      "id": "database",
      "apps":[
            {
              "container": {
                "type": "DOCKER",
                "docker": {
                  "image": "busybox",
                  "network": "BRIDGE",
                  "privileged": true,
                  "parameters": [
                      { "key": "tty", "value": "true" }
                  ]
                }
              },
              "id": "database",
              "instances": 2,
              "cpus": 1,
              "mem": 64
            }
      ]
   }
   ]
}

I now want to publish my application:

curl -X POST "http://marathon.mesos:8080/v2/groups" -H "content-type: application/json" -d@group.json

Once posted you will see this below with a folder icon:

Marathon Group database

As you click deeper, you will find this:

Marathon Group database

If you click on database, you will see this:

Marathon Group database

When you click further you will this all the database instances running:

Marathon Group database

Here are some documentation about this process here:
https://mesosphere.github.io/marathon/docs/application-groups.html

If you wanted to use Mesos-DNS with Marathon groups to reach these services. You will use this naming convention:
database-database-marathon-group-test.marathon.mesos

*Note Mesos-DNS resolves in reverse order by hierarchy

Popular Tags

    More blogs on this topic

      Archive

        Industry & topics highlighted

        Technology