Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use port mapping with docker driver #8770

Closed
leonardoarroyo opened this issue Aug 28, 2020 · 9 comments
Closed

Can't use port mapping with docker driver #8770

leonardoarroyo opened this issue Aug 28, 2020 · 9 comments
Assignees
Labels
stage/waiting-reply theme/docs Documentation issues and enhancements theme/networking

Comments

@leonardoarroyo
Copy link

Nomad version

Nomad v0.12.1 (14a6893)

Operating system and Environment details

Linux i5 5.7.12-arch1-1 #1 SMP PREEMPT Fri, 31 Jul 2020 17:38:22 +0000 x86_64 GNU/Linux

Issue

I can't seem to run a basic docker container and map the ports. Using ports config gives an error, it seems to be accepting the port_map configuration but it's odd because the docs here says I should be using the ports syntax.

Reproduction steps

Running the following job will give you a "pending" status.

Job file (if appropriate)

job "webservice" {
  datacenters = ["dc1"]

  group "example" {
    network {
      port "web" { to = 8080 }
    }
    task "server" {
      driver = "docker"

      config {
        image = "hashicorp/http-echo"
        args  = ["-text", "hello world"]
        ports = ["web"]
      }

      resources {
        cpu = 20
      }
    }
  }
}

The following job file gives a running state but maps the wrong port.

job "webservice" {
  datacenters = ["dc1"]

  group "example" {
    task "server" {
      driver = "docker"

      config {
        image = "hashicorp/http-echo"
        args  = ["-text", "hello world"]
        port_map {
          http = 8080
        }
      }

      resources {
        cpu = 20

        network {
          mbits = 100
          port "http" {}
        }
      }
    }
  }
}
$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                            NAMES
5517411e69a8        hashicorp/http-echo   "/http-echo -text 'h…"   11 seconds ago      Up 10 seconds       5678/tcp, 127.0.0.1:30404->8080/tcp, 127.0.0.1:30404->8080/udp   server-51f6c653-f704-9b49-24ed-2d7499dafda9

Nomad Client logs (if appropriate)

When running nomad alloc status I get:

Recent Events:
Time                       Type               Description
2020-08-27T21:00:58-03:00  Killing            Sent interrupt. Waiting 5s before force killing
2020-08-27T21:00:56-03:00  Alloc Unhealthy    Unhealthy because of failed task
2020-08-27T21:00:56-03:00  Not Restarting     Error was unrecoverable
2020-08-27T21:00:56-03:00  Failed Validation  2 errors occurred:
        * failed to parse config: 
        * Invalid label: No argument or block type is named "ports".
2020-08-27T21:00:56-03:00  Task Setup         Building Task Directory
2020-08-27T21:00:56-03:00  Received           Task received by client

Nomad Server logs (if appropriate)

@leonardoarroyo
Copy link
Author

Okay, I was able to get the basic container up with the following file:

job "webservice" {
  datacenters = ["dc1"]

  group "example" {
    task "server" {
      driver = "docker"

      config {
        image = "hashicorp/http-echo"
        args  = ["-text", "hello world"]
        port_map {
          http = 5678
        }
      }

      resources {
        cpu = 20

        network {
          mbits = 100
          port "http" {
            static = 8080
          }
        }
      }
    }
  }
}

The fact that the newer syntax doesn't work and I can't seem to find documentation for the deprecated port_map(had to combine info I gathered around the web) is odd though. Wondering if I rushed through the docs and I'm missing something here.

@tgross
Copy link
Member

tgross commented Aug 28, 2020

Hi @leonardoarroyo! Sorry about that, I think you're running into the same sort of documentation problems folks are running into in #8747 and #8746. I'm going to tag-in my colleagues @nickethier and @shoenig here as they've been working on this area lately and probably can best answer what's the best way forward.

@tgross tgross added theme/networking theme/docs Documentation issues and enhancements stage/needs-investigation labels Aug 28, 2020
@nickethier nickethier self-assigned this Aug 28, 2020
@jsardev
Copy link

jsardev commented Aug 28, 2020

Have the same issue. Unfortunately the examples from the docs are not working as described. Also, I noticed that ports declared in job -> group -> network are not detected in job -> group -> task -> service - I get a port label "XXXX" referenced by services XXXX does not exist.

@nickethier
Copy link
Member

Hey @leonardoarroyo

The syntax you have in your original issue is correct but was introduced in v0.12.2.

Declaring the network resource in the task is deprecated which is why the documentation is missing. I've done some work to improve that and hopefully lessen confusion in #8743 which hasn't been merged yet.

Could you try your original job definition with a newer version?

@kpweiler
Copy link

I'm having the same issue as @sarneeh on defining services at the task level - is there a separate ticket for that?

@nickethier
Copy link
Member

This issue should have been fixed in #8623. @kpweiler could you open up a new issue if you're experiencing an issue with defining services. Thanks!

@kpweiler
Copy link

I see this is in v0.12.5 (I'm running v0.12.3) - I'm sure that's the issue. My bad - thanks!

@fuleow
Copy link

fuleow commented Dec 4, 2020

Have the same issue. Unfortunately the examples from the docs are not working as described. Also, I noticed that ports declared in job -> group -> network are not detected in job -> group -> task -> service - I get a port label "XXXX" referenced by services XXXX does not exist.

I ran into this issue as well with 0.12.5. Services must be declared at the group level otherwise you'll get this error. This was surprising and I would have expected services at the task level to be deprecated alongside the network change if this is the intended behavior.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stage/waiting-reply theme/docs Documentation issues and enhancements theme/networking
Projects
None yet
Development

No branches or pull requests

6 participants