Networking between multiple containers within a job

1,996 views
Skip to first unread message

Chris Lajoie

unread,
Jun 29, 2017, 1:04:39 PM6/29/17
to Nomad
Hi, I have set up a Consul/Nomad cluster and I'm pretty impressed with the capabilities so far. Also love the fact that everything goes into a single binary.. this makes it easy to deploy.
I have deployed a few single-container jobs on Nomad no problem. But now I'm trying to do a small PHP application that consists of 2 containers: one running php-fpm and the other running nginx. Nginx needs to be able to communicate with the php-fpm container in order to serve up the site. This kind of container-to-container linking was trivial in docker-compose, but now I need to deploy it on Nomad. It seems like Nomad is designed for this kind of thing (at least, the concept of "groups" in Nomad jobs makes me think so) but I can't find any examples of this being done. Can anyone enlighten me?

Chris

Brian Lalor

unread,
Jun 29, 2017, 1:10:49 PM6/29/17
to Chris Lajoie, Nomad
There are environment variables named according to the tasks in the group, and you can use those to look up the IP address and port for inter-task communication.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/nomad/issues
IRC: #nomad-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Nomad" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nomad-tool+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nomad-tool/9bb37c92-ae32-4f8b-8cdb-3ebaad8b5785%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

— 
Brian Lalor

signature.asc

Armon Dadgar

unread,
Jun 29, 2017, 1:45:09 PM6/29/17
to Brian Lalor, Chris Lajoie, Nomad
Adding to what Brian said, this page documents the environment variables: https://www.nomadproject.io/docs/runtime/environment.html

For example, if you create a task group like:

Job “Foo” {
  Group “web” {
    Task “nginx” {…}
    Task “php” {… network { port “http” { … } }
  }
}

Then the Nginx app can resolve with “NOMAD_ADDR_php_http” environment variable.

Best Regards,
Armon Dadgar

Chris Lajoie

unread,
Jun 29, 2017, 3:11:24 PM6/29/17
to Nomad
Got it, thanks!
Reply all
Reply to author
Forward
0 new messages