0

I got a issue in Marathon. There are 2 situations

  1. Run docker-compose-up -d in Ubuntu command interface.

    It run and deploy application successfully.

  2. Run docker-compose-up -d in Marathon Json file

    {
      "id":"/piggy-demo-beta",
      "cmd":"cd /home/ubuntu/spring-demo2 && sudo docker-compose up -d ",
      "cpus":1,
      "mem":4200,
      "disk":0,
      "instances":1,
      "acceptedResourceRoles":[
        "slave_public"
      ],
      "portDefinitions":[
        {
          "port":10000,
          "protocol":"tcp",
          "labels":{}
        }
      ]
    }
    

Then it can't deploy and the Marathon always transform the state around Waiting, Delayed and Running. When I touch sudo ps -a in the server, it appears that the container restarting ceaselessly.

docker ps

And in the Mesos, the same task finished a lot of times.

Mesos interfaces

Here is the compose.yml file.

version: '2'
services:
  rabbitmq:
    image: rabbitmq:3-management
    restart: always
    ports:
      - 15672:15672
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  config:
    environment:
      CONFIG_SERVICE_PASSWORD: $CONFIG_SERVICE_PASSWORD
    image: sqshq/piggymetrics-config
    restart: always
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  registry:
    environment:
      CONFIG_SERVICE_PASSWORD: $CONFIG_SERVICE_PASSWORD
    image: sqshq/piggymetrics-registry
    restart: always
    ports:
      - 8761:8761
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  gateway:
    environment:
      CONFIG_SERVICE_PASSWORD: $CONFIG_SERVICE_PASSWORD
    image: sqshq/piggymetrics-gateway
    restart: always
    ports:
      - 80:4000
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  auth-service:
    environment:
      CONFIG_SERVICE_PASSWORD: $CONFIG_SERVICE_PASSWORD
      NOTIFICATION_SERVICE_PASSWORD: $NOTIFICATION_SERVICE_PASSWORD
      STATISTICS_SERVICE_PASSWORD: $STATISTICS_SERVICE_PASSWORD
      ACCOUNT_SERVICE_PASSWORD: $ACCOUNT_SERVICE_PASSWORD
      MONGODB_PASSWORD: $MONGODB_PASSWORD
    image: sqshq/piggymetrics-auth-service
    restart: always
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  auth-mongodb:
    environment:
      MONGODB_PASSWORD: $MONGODB_PASSWORD
    image: sqshq/piggymetrics-mongodb
    restart: always
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  account-service:
    environment:
      CONFIG_SERVICE_PASSWORD: $CONFIG_SERVICE_PASSWORD
      ACCOUNT_SERVICE_PASSWORD: $ACCOUNT_SERVICE_PASSWORD
      MONGODB_PASSWORD: $MONGODB_PASSWORD
    image: sqshq/piggymetrics-account-service
    restart: always
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  account-mongodb:
    environment:
      INIT_DUMP: account-service-dump.js
      MONGODB_PASSWORD: $MONGODB_PASSWORD
    image: sqshq/piggymetrics-mongodb
    restart: always
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  statistics-service:
    environment:
      CONFIG_SERVICE_PASSWORD: $CONFIG_SERVICE_PASSWORD
      MONGODB_PASSWORD: $MONGODB_PASSWORD
      STATISTICS_SERVICE_PASSWORD: $STATISTICS_SERVICE_PASSWORD
    image: sqshq/piggymetrics-statistics-service
    restart: always
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  statistics-mongodb:
    environment:
      MONGODB_PASSWORD: $MONGODB_PASSWORD
    image: sqshq/piggymetrics-mongodb
    restart: always
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  notification-service:
    environment:
      CONFIG_SERVICE_PASSWORD: $CONFIG_SERVICE_PASSWORD
      MONGODB_PASSWORD: $MONGODB_PASSWORD
      NOTIFICATION_SERVICE_PASSWORD: $NOTIFICATION_SERVICE_PASSWORD
    image: sqshq/piggymetrics-notification-service
    restart: always
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  notification-mongodb:
    image: sqshq/piggymetrics-mongodb
    restart: always
    environment:
      MONGODB_PASSWORD: $MONGODB_PASSWORD
    logging:
      options:
        max-size: "10m"
        max-file: "10"

  monitoring:
    environment:
      CONFIG_SERVICE_PASSWORD: $CONFIG_SERVICE_PASSWORD
    image: sqshq/piggymetrics-monitoring
    restart: always
    ports:
      - 9000:8080
      - 8989:8989
    logging:
      options:
        max-size: "10m"
        max-file: "10"
  • 1
    I think running `docker compose` on Marathon is not the best idea. You should translate compose to marathon groups json and deploy that group. – janisz Oct 13 '16 at 13:28
  • could you please provide some example or detail information about how to translate compose.yml to marathon group json? thanks very much! – Jesse Zhen Oct 13 '16 at 16:42
  • Running docker-compose inside a container running via Marathon doesn't make any sense to be honest. What do you actually want to do? – Tobi Oct 13 '16 at 19:00

1 Answers1

1

To run group of application that were set up with docker compose on Marathon you should translate each of your service into Marathons application. Every filed from compose.yaml has its equivalent in Marathon app.

Example Lets assume we want to run some big application called piggy that is build from many smaller services. One service is define as

  rabbitmq:
    image: rabbitmq:3-management
    restart: always
    ports:
      - 15672:15672
    logging:
      options:
        max-size: "10m"
        max-file: "10"

will result in

{
  "id":"piggy/rabbitmq",
  "container":{
    "docker":{
      "image":"rabbitmq:3-management",
      "network":"BRIDGE",
      "portMappings":[{
          "containerPort":8761,
          "hostPort":0
      }],
      "parameters":[
        {
          "key":"max-size",
          "value":"10,"
        },
        {
          "key":"max-file",
          "value":"10"
        }
      ]
    },
    "type":"DOCKER"
  },
  "cpus":1.0,
  "mem":512.0,
  "instances":1
}

This process need to be repeated for each service defined in compose.yaml. Prepared JSONs should be POST /v2/apps or grouped together in Marathon group.

If you take a close look you can see it's not 1 to 1 translation. In compose.yaml there are not defined resources cpus/mem. Another difference it port mapping. When you run service on Mesos you shouldn't statically allocate ports. That's why host port is set to 0 so random port will be assigned. Another important thing is healthchecking. You should define healthchecks for your application. And last is volumes. When running services on Mesos and they require files to persists you should investigate persistent volumes.

janisz
  • 6,292
  • 4
  • 37
  • 70
  • thanks a lot ! In docker server, I run this application by the command of `docker-compose-up -d`,the `-d` is necessary for this application. If I don't add the `-d` , it will promote error code. I try to run some single service in the marathon, some of the service would promote the error code just like the situation when i don't add -d in the server command. So in the marathon json file, how to add the `-d` for each single service? – Jesse Zhen Oct 16 '16 at 07:55
  • Any additional docker parameter could be passed in `parameters` map just like `max-size`. I doubt detached is the real reason why service fails. I suspect it's becouse one of your services try to connect with another and can't find it due to random host/port. – janisz Oct 16 '16 at 09:28
  • Thanks! I follow the guides of yours, it seems good. But when I use marathon to run a detach container, it repeatedly run so many containers ceaselessly. – Jesse Zhen Oct 17 '16 at 06:57
  • `"parameters":[ { "key":"detach", "value":"true" }` – Jesse Zhen Oct 17 '16 at 06:58
  • For this container, it must run as the way of detach, otherwise it would can't run successfully. – Jesse Zhen Oct 17 '16 at 07:00