0

docker client for docker ps has very useful flag -l which shows container information which was run recently. However all other docker commands requires providing either CONTAINER ID or NAME.

Is there any nice trick which would allow to call:

docker logs -f -l

instead of:

docker logs -f random_name

3 Answers 3

3

You can you docker logs -f `docker ps -ql`

1

For the last container docker ps -n 1 or variants such as docker ps -qan 1 can be handy

0

After a while playing with docker tutorial, I created small set of aliases:

alias docker_last="docker ps -l | tail -n +2 | awk '{ print \$(NF) }' | xargs docker $1"
alias docker_all="docker ps -a | tail -n +2 | awk '{ print \$(NF) }' | xargs docker $1"
alias docker_up="docker ps | tail -n +2 | awk '{ print \$(NF) }' | xargs docker $1"
alias docker_down="docker ps -a | tail -n +2 | grep -v Up | awk '{ print \$(NF) }' | xargs docker $1"

Which allow to call command on last, all, up and down containers:

docker_last logs # Display logs from last created container
docker_down rm   # Remove all stopped containers
docker_up stop   # Stop all running containers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.