How to send Docker container logs from Azure App Service to Seq log server?
Asked Answered
P

1

16

My website uses a docker container, and I host it on Azure using an Azure App Service. I use a Seq log server to centralize logging.

How can I send the Docker container logs from my Azure App Service to my Seq log server?

I am afraid that the answer might be that this is impossible. The "proper" way to send Docker container logs to a Seq log server includes adding some arguments to the docker run command, but I can't find any way to provide such arguments in the Azure App Service or the corresponding Azure Web App Service for Container task that I use to deploy a new container image to that service.

One reason I want the docker logs sent to Seq is that I think the handling of logs by Azure is confusing. This question contains many answers about how one might claw some docker logs out of Azure, but none would be as simple or complete as searching for "docker" in a Seq log server.


Maybe Azure App Service isn't the correct tool for the job. Instead, maybe I should be using Azure Container Instance (ACI). The integration with Docker seems strong. However, this answer says

Azure Web App for Containers is targeted at long running stuff (always running) while ACI are aimed at scheduled\burstable\short lived workloads (similar to Azure Functions).

My website should always be running, so this makes me think that I am correctly using Azure App Service.


Maybe I should deploy to my Azure App Service using the Docker task. However, two things make me think otherwise. The first is that the task says:

Use this task to build and push Docker images to any container registry using Docker registry service connection.

[...]

This task can also be used to control job and service containers. This usage is uncommon, but occasionally used for unique circumstances.

Also, my Azure App Service includes many arguments when it executes docker run. I don't know what they all do, and don't know what I would need to include to make things work correctly.


Maybe these options that are configurable via arguments to docker run can be hardcoded with a Docker image when it is created. However, I haven't found any suggestion that this is possible.


One of the arguments to docker run that I care about is --log-driver. The default log driver for a Docker container can be set via the daemon.json configuration file. Maybe the Docker container associated with my Azure App Service can be configured via this configuration file. However, I haven't found any way to do this.

Pie answered 2/2, 2022 at 2:44 Comment(3)
How are you hosting the Seq server? As far as I know, you can either host it in the same instance by using docker-compose or host it in it's own app service.Minnich
I am currently hosting it in a separate Azure App Service, but I am running to change that to solve this problem.Pie
...but I am willing to change that...Pie
T
0

Configure Seq to accept GELF format logs (note that you can use the Seq.Input.Gelf app if you don't want to run a second container).

Then configure your container to use GELF logging using something like:

docker run \
    --rm \
    -it \
    --log-driver gelf \
    --log-opt gelf-address=udp://seq.example.com:12201 \
    hello-world:latest

(from the Seq documentation)

In this example, --log-driver gelf instructs Docker to output logs using the GELF logging driver, while --log-opt gelf-address=udp://seq.example.com:12201 directs Docker to send logs via UDP to the specified host/port pair.

Transmission answered 2/2, 2022 at 8:5 Comment(4)
"...using something like..." I don't know what you mean here. Can you elaborate? It is easy to do this when I execute docker run on my local computer. What I don't know how to do is provide the --log-driver and -log-opt arguments to the docker run command that Azure executes in my Azure App Service.Pie
Hello @liammclennan. Did you see my previous comment?Pie
It looks like Azure App Service may not support docker run flags. You can set environment variables, but not flags.Transmission
Yes, that is also my impression. Could you remove this answer? I think that might help me find a solution.Pie

© 2022 - 2024 — McMap. All rights reserved.