Thursday, 14 February 2019

Redirection docker logs


docker container run --detach --env MYSQL_RANDOM_ROOT_PASSWORD=yes --name johnsmysql --publish 3307:3306 mysql

# Search for GENERATED PASSWORD from mySQL logs
docker container logs --follow johnsmysql 2>&1 | grep GENERATED
2 refers to the second file descriptor of the process, i.e. stderr.
> means redirection.
&1 means the target of the redirection should be the same location as the first file descriptor, i.e. stdout.
So > /dev/null 2>&1 first redirects stdout to /dev/null and then redirects stderr there as well. This effectively silences all output (regular or error) from the wget command.

No comments:

Post a Comment