Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep nomad task from exiting?

Tags:

devops

nomad

In docker we have -t flag to keep containers from exiting. How can achieve the same thing in nomad?

I want to debug if I can ping one service from another, so I just want a container with curl. However, if I try to deploy the ubuntu image specifying it like below it exits and keeps restarting. What can I do so it just keeps running?

task "testubuntu" {

  driver = "docker"

  config {
      image = "ubuntu:latest"
  }

  resources {
      cpu = 500
      memory = 256
      network {
          mbits = 10
      }
  }
}
like image 229
Alan Sereb Avatar asked Nov 07 '22 05:11

Alan Sereb


1 Answers

Another solution would be to set a "dummy" entry point tail -f /dev/null

task "testubuntu" {

  driver = "docker"

  config {
      image = "ubuntu:latest"
      entrypoint = [
          "tail", "-f", "/dev/null",
      ]
  }

  resources {
      cpu = 500
      memory = 256
  }
}

It is particularly useful, when you have a task that errors at the container startup but there is not much useful information in the logs. This "dummy" entry point will keep container alive allowing you to get inside container and execute a real startup command with attached debugger for example.

Apart from tail -f /dev/null, you can also simply use yes as an entry point. However, it will pollute stdout and affect your logging solution if it is setup.

like image 152
Ilya Kisil Avatar answered Dec 06 '22 14:12

Ilya Kisil