Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

docker compose logs container stdout

init-app.sh:

#!/usr/bin/env sh

# Exit script immediately if a command exits with a non-zero status.
set -e

# Install and configure app
[...]

# Start app
exec ./app
The above configuration works, but outputs only to stdout.

Modification #1 (last line of init script):

# Start app and log output to file
exec ./app >> "/app/log.txt" 2>&1
This configuration works also, logging the output to a file, but not to stdout.

Modification #2 (last line of init script):

# Start app and log output to both a file and stdout
exec ./app 2>&1 | tee -a "/app/log.txt"
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #docker #compose #logs #container #stdout
ADD COMMENT
Topic
Name
1+1 =