hashicorp / nomad

Nomad is an easy-to-use, flexible, and performant workload orchestrator that can deploy a mix of microservice, batch, containerized, and non-containerized applications. Nomad is easy to operate and scale and has native Consul and Vault integrations.
https://www.nomadproject.io/
Other
14.81k stars 1.94k forks source link

Nomad doesn't show task logs #7006

Closed ghost closed 4 years ago

ghost commented 4 years ago

dnsproxy.nomad:

job "dnsproxy" {

    datacenters = [ "dc1" ]

    type = "service"

    group "dnsproxy-group" {
        count = 1
        task "dnsproxy-task" {
            driver = "docker"
            # Configuration is specific to each driver.
            config {
                image = "dnsproxy:0.23.7"
                args = [
                    "-u", "[/consul/]${NOMAD_IP_dns}:8600",
                    "-u", "tls://dns.adguard.com", 
                    "--cache", "--cache-size=32768"
                ]
                port_map {
                    dns = 53
                }
            }

            resources {
                network {
                    mode = "bridge"
                    port "dns" {
                        static = 53
                    }
                }
                cpu     = 1000 #MHz
                memory  = 100 #MB
            }

            # The service block tells Nomad how to register
            # this service with Consul for service discovery and
            # monitoring.
            service {
                name = "dnsproxy"
                port = "dns"
                check {
                    type     = "tcp"
                    interval = "5s"
                    timeout  = "2s"
                }
            }
        }
    }
}

Dockerfile for dnsproxy image:

FROM golang:1.13.6-alpine as base

RUN apk add --no-cache --virtual .build-deps git
#clone repo
ARG  DNSPROXY_VERSION="v0.23.7"
RUN git clone --depth 1 --branch ${DNSPROXY_VERSION} https://github.com/AdguardTeam/dnsproxy.git /app
RUN apk del --purge .build-deps 
WORKDIR /app
RUN go build

FROM alpine:3.10
WORKDIR /
COPY --from=base /app/dnsproxy /
RUN apk add --no-cache libcap && setcap cap_net_bind_service+ep /dnsproxy && apk del libcap
USER nobody
ENTRYPOINT ["/dnsproxy"]
CMD ["-u", "tls://dns.adguard.com", "--cache", "--cache-size=32768"]

No logs displayed with the following command:

nomad alloc logs -f <alloc_id>

However, logs are available using direct docker command:

$ docker logs -f <container_id>
2020/01/29 10:21:49 [info] Starting the DNS proxy
2020/01/29 10:21:49 [info] Upstream 0: 10.237.27.6:8600 is reserved for next domains: consul.
2020/01/29 10:21:49 [info] Upstream 1: dns.adguard.com:853
2020/01/29 10:21:49 [info] Starting the DNS proxy server
2020/01/29 10:21:49 [info] DNS cache is enabled
2020/01/29 10:21:49 [info] Creating the UDP server socket
2020/01/29 10:21:49 [info] Listening to udp://[::]:53
2020/01/29 10:21:49 [info] Creating the TCP server socket
2020/01/29 10:21:49 [info] Listening to tcp://[::]:53
2020/01/29 10:21:49 [info] Entering the UDP listener loop on [::]:53
2020/01/29 10:21:49 [info] Entering the tcp listener loop on [::]:53
ghost commented 4 years ago

I figured out cause of this problem. It is necessary to pass explicit -stderr option and it is quite confusing. At least it is non-conformant with docker logs behaviour.

nomad alloc logs -stderr -f <alloc_id>
tgross commented 4 years ago

Hi @Genesis0x1b! You're right that it doesn't quite match docker logs, but it is intentional. Not co-mingling stdout and stderr lets you pipe nomad alloc logs to other unix processes, and in general makes log shipping more tunable for production workloads.

ghost commented 4 years ago

Hi @tgross ! Thank you for your response. ok, it makes sense.

github-actions[bot] commented 1 year ago

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.