Docker Dependency using Mesosphere's Marathon Groups
mesosphere.com

Docker Dependency using Mesosphere's Marathon Groups

 

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 "https://marathon.mesos:8080/v2/groups" -H "content-type: application/json" [email protected] 

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

 As you click deeper, you will find this:

If you click on database, you will see this:

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

 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

要查看或添加评论,请登录

社区洞察

其他会员也浏览了