I have a docker container based on Postgres's official docker image. I want to see the incoming queries when I look at the logs of the docker container using docker logs -f
. This is my Dockerfile:
FROM postgres:11.1-alpine COPY mock_data.sql /docker-entrypoint-initdb.d/mock_data.sql ENV PGDATA=/data
and this is the part of my docker-compose.yml file related to this service:
version: '3' services: mock_data: image: mock_data container_name: mock_data ports: - 5434:5432/tcp
What is the eaasiest way to include the incoming queries in docker logs?
First of all, to list all running containers, use the docker ps command. Then, with the docker logs command you can list the logs for a particular container. Most of the time you'll end up tailing these logs in real time, or checking the last few logs lines.
Viewing Container Logs You can use docker ps -a to get the IDs and names of your containers. The logs command prints the container's entire log output to your terminal. The output will not be continuous. If you'd like to keep streaming new logs, add the --follow flag to the command.
If using Docker Compose, you can add this line to your docker-compose.yaml file:
command: ["postgres", "-c", "log_statement=all"]
and all your queries will be written into the container log file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With