In that kind of scenario, the best way to that is to use the "loki-docker-driver" client. It's very convenient to use and it automatically will label all of your containers' logs with their respective container names.
So, querying the ERROR logs of a container with container id "1234", will just have this simple query:
{container_name="1234"} |~ "ERROR"
I have planned to write an article on how to use loki-docker-driver too. So, stay tuned for that :)
Meanwhile, if you still would like to know about it, check this out - https://grafana.com/docs/loki/latest/clients/docker-driver/