🕌

nomadで普通にDockerコンテナを動かすサンプル

2021/03/15に公開

自分の探し方が悪いのか簡単なDockerコンテナを動かすサンプルが無かったので掲載しておく。
Install Nomad のインストールを普通にやって、このコンフィグをrunすれば(http://localhost/top.html)でWelcomeが見える。

job "httpd2" {
  datacenters = ["dc1"]
  type = "service"

  group "front" {
    count = 1
    network {
      port "http" {
        static = 80
      }
    }
    service {
      name = "nginx-httpd"
      port = "http"
    }
    restart {
      attempts = 2
      interval = "30m"
      delay = "15s"
      mode = "fail"
    }
    ephemeral_disk {
      size = 300
    }
    task "nginx" {
      driver = "docker"
      config {
        image = "nginx:latest"
        ports = ["http"]
        volumes = [
          "local/top.html:/usr/share/nginx/html/top.html",
        ]
      }
      resources {
        cpu    = 500 # 500 MHz
        memory = 256 # 256MB
      }

      template {
        change_mode = "noop"
        destination = "local/top.html"

        data = <<EOH
<h1>Welcome</h1>
EOH
      }

    }
  }
}

参考リンク

Dockerドライバのドキュメント
https://www.nomadproject.io/docs/drivers/docker

コンテナに環境変数を渡す設定
https://www.nomadproject.io/docs/job-specification/env

Discussion