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
daniula
  • 6,898
  • 4
  • 32
  • 49

3 Answers3

3

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

creack
  • 116,210
  • 12
  • 97
  • 73
1

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

user2915097
  • 30,758
  • 6
  • 57
  • 59
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
daniula
  • 6,898
  • 4
  • 32
  • 49