9

when I run a docker container as a marathon job, it creates a docker container in the active mesos slave system. when suspend or destroy the docker job what I expect that marathon should delete the docker container as its no longer required. But the container does not get deleted. I have to delete them manually every time marathon restart a docker container job.

is there any way to delete these unwanted containers automatically?

Edit: Adding json file for initiating a marathon job

{
  "id": "pga-docker",
  "cmd":"sh pga-setup.sh",
  "cpus": 0.5,
  "mem": 1024.0,
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "pga:test",
      "parameters": [
        { "key": "env", "value": "SERVER_HOST=value" },
        { "key": "env", "value": "SERVER_PORT=value" }
      ],
      "network": "BRIDGE",
      "portMappings": [
        { "containerPort": 80, "hostPort": 0}
      ]
    }
  }
}
psaha4
  • 339
  • 3
  • 17
  • which mesos version you use? – haosdent Jul 31 '15 at 04:20
  • I check current mesos code, the container should be removed. – haosdent Jul 31 '15 at 04:24
  • I am observing the same behavior for destroyed apps. Not sure if it's Marathon issue or mesos-slave issue. – Dharmit Jul 31 '15 at 08:43
  • my mesos 0.22.1, I am using command line json file to instantiate a job in marathon. but when i do destroy the app its not deleting the container from the host system, not even stopping the container. so i started believing that once marathon job is started is has no relation to dockers in the hosting system. But i was wrong, because when i stop a container by force through "docker stop" command, i could see immediately marathon starts a new container again, which is expected marathon job behavior. so may be something wrong with the approach, i am attaching my json file feel fre to crrct me. – psaha4 Jul 31 '15 at 15:05

2 Answers2

1

Marathon will restart a docker container which failed so that you have the number of instances you requested. It could be that you see stopped/failed containers which were not cleaned up by Mesos. This could be related to the fact that Mesos delays container cleanup until GC. see https://issues.apache.org/jira/browse/MESOS-1656

Aliza
  • 734
  • 1
  • 10
  • 25
0

It is the behavior of Marathon, because it is meant for long running services, as soon the task is completed, Marathon assumes it has been terminated in that host and immediately it will assign a new instance for running the application. If you need one of task you can use Chronos, so it makes the task to run only one time. I have written a script to do this automatically for marathon.

start=$1
end=$2
for (( c=$start; c<=$end; c++ ))
do

         echo "deleting:$c"
         sleep 10
         var=$(curl -X GET http://localhost:8080/v2/apps/docker-app-$c | grep "startedAt")
         echo "$var"
         if [[ $var == *"startedAt"* ]]
         then
          curl -X DELETE http://localhost:8080/v2/apps/docker-app-$c
          echo "going to delete"
         else
                echo "application not started yet"
         fi

 sleep 1
done
echo "Completed!"