1

I have not been able to connect the containers of my app and promtail via volumes so that promtail can read it.

I have an app that creates log files (by log4j2 in java ) to a folder with the extension appXX.log, when I share volumes my app is not able to write this file.

Here is my docker-compose (I have skipped the loki/grafana containers).

My app writes fine in that path without the shared volume, so it must be somehow how docker manages the volumes. Any ideas what could be going on?

   promtail:
    image: grafana/promtail:2.4.1
    volumes:
      - "app-volume:/var/log/"
      - "path/config.yml:/etc/promtail/config.yml"
    command: -config.file=/etc/promtail/config.yml

   app:
    image: app/:latest
    volumes:
      - "app-volume:/opt/app/logs/"
    command: ["/bin/sh","-c","java $${JAVA_ARGS} -jar app-*.jar"]

volumes:
     app-volume: 

On the other hand, I do not know if it is the correct way to log an application to promtail, I have seen that usually read directly the log of the container (which does not work for me, because it only works in docker-linux) and I can think of these other possibilities What would be the right one in case it is impossible by volumes?

other alternatives

Any idea is welcome, thanks !

Illidan
  • 149
  • 1
  • 8
  • What's the specific problem you're running into? Are the two containers running as root or as some other user(s)? I'd generally recommend logging to stdout, not a file, where the logs can be picked up by `docker logs`. You seem to acknowledge this approach in your last paragraph; what problems do you run into if you try this? (You don't mention your host OS, but I'd expect the native-Linux approach to also work on Docker Desktop for Mac and on VM-based solutions, no specific experience with Windows.) – David Maze Jan 31 '22 at 21:40
  • Both containers should run as root if . The problem comes when linking the volumes, that promtail's volume "overwrites" my application's volume, and promtail is unable to write. I was referring to directly using docker drivers (which is not supported on windows) https://grafana.com/docs/loki/latest/clients/docker-driver/ . Read directly from docker stdout I haven't tried it yet.Would I need to run as sudo my promtail container to be able to see the stdout of the containers ? or it is not necessary to get up all with the same user in the docker-compose ? – Illidan Jan 31 '22 at 22:02

0 Answers0