I have been trying to get logs in format:
{"log":"Using CATALINA_BASE: /opt/apache-tomcat-
7.0.76\r\n","stream":"stdout","time":"2017-04-
19T04:28:33.608418994Z","attrs":
{"production_status":"testing","os":"ubuntu"}}
I am using docker-compose.yml :
version: '2.1'
services:
web:
image: hello-world/web:latest
container_name: api
ports:
- "80:8080"
logging:
driver: "json-file"
options:
max-size: 10m
max-file: "3"
labels: testing
env: ubuntu
But I do not get "attrs" key in logs. What am I doing wrong?
When you start a container, you can configure it to use a different logging driver than the Docker daemon's default, using the --log-driver flag. If the logging driver has configurable options, you can set them using one or more instances of the --log-opt <NAME>=<VALUE> flag.
To use the json-file driver as the default logging driver, set the log-driver and log-opts keys to appropriate values in the daemon. json file, which is located in /etc/docker/ on Linux hosts or C:\ProgramData\docker\config\ on Windows Server. If the file does not exist, create it first.
By default, Docker stores log files in a dedicated directory on the host using the json-file log driver. The log file directory is /var/lib/docker/containers/<container_id> on the host where the container is running. In the above output, we can see that the data is in JSON format.
depends_on is a Docker Compose keyword to set the order in which services must start and stop. For example, suppose we want our web application, which we'll build as a web-app image, to start after our Postgres container.
Based on my testing, there are 2 pieces to get the labels/environment variables show up in the logs.
So, to get what you want, you need to set the docker-compose.yml to:
version: '2.1'
services:
web:
image: hello-world/web:latest
container_name: api
ports:
- "80:8080"
logging:
driver: "json-file"
options:
max-size: 10m
max-file: "3"
labels: "production_status"
env: "os"
labels:
production_status: "testing"
environment:
- os=ubuntu
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