How to configure hashicorp nomad network part?

Hi There!

I want to use nomad to replace docker-compose. In docker compose, you can specify the dependent containers and you will be able to reach the container with the name.

# DB Container
db:
    image: 'mysql:8.0'
    ....

# App Container
app:
    .....
    depends_on:
        - db

Things doesn’t seem that easy with nomad somehow! it feels i have to dig deep to understand the networking part or use consul. I have this basic test job that creates mysql container and another application container.

    job "hippo_services_db" {
      datacenters = ["dc1"]
    
      group "services" {
    
        volume "mysql_data" {
          type      = "host"
          read_only = false
          source    = "mysql_data"
        }
    
        network {
          port "mysql_srv" {
            static = 3306
          }
          port "toad_srv" {
            static = 8080
          }
        }
    
        task "mysql" {
          driver = "docker"
    
          volume_mount {
            volume      = "mysql_data"
            destination = "/var/lib/mysql"
            read_only   = false
          }
    
          config {
            image = "mysql:8.0"
    
            ports = ["mysql_srv"]
          }
    
          env {
              MYSQL_ROOT_PASSWORD = "root"
              MYSQL_DATABASE = "hippo"
              MYSQL_USER = "hippo"
              MYSQL_PASSWORD = "m06rs011e9h9ihuboi7s"
              MYSQL_ALLOW_EMPTY_PASSWORD = "no"
          }
    
          resources {
            cpu    = 100
            memory = 900
          }
        }
    
        task "toad" {
          driver = "docker"
    
          config {
            image = "clivern/toad:release-0.2.4"
    
            ports = ["toad_srv"]
    
            command = "./toad"
    
            args = [
              "--port",
              "${NOMAD_PORT_toad_srv}",
            ]
          }
    
          env = {
            IS_STATEFUL    = "false",
          }
    
          resources {
            network {
              mbits = 10
            }
          }
        }
      }
    }

from the application container toad i want to access the mysql container. You can install mysql client inside toad container as explained below. so far i can’t reach the database container from the app container.

$ docker ps
# Get the toad app container id
$ docker exec -it $ID bash
$ apt-get update && apt-get install -y git curl libmcrypt-dev default-mysql-client
$ mysql -h $IP -P 3306 -u root -proot

I am struggling with this for a day or so! any help would be much appreciated!

I managed to get things working with consul. seems that’s the only way. But running containers lose internet connectivity!!

Finally all my issues got solved! i was using old version 0.8.0 of CNI plugins :smiley:

2 Likes