Skip to content

Instantly share code, notes, and snippets.

@ramkumardevanathan
Created November 25, 2014 03:31
Show Gist options
  • Save ramkumardevanathan/d25bb91d8ab170d3b656 to your computer and use it in GitHub Desktop.
Save ramkumardevanathan/d25bb91d8ab170d3b656 to your computer and use it in GitHub Desktop.
simple gist to get docker ps output as csv file
docker ps -a --no-trunc | awk -F " +" '{$1=$1}1' OFS="\t"
@e-ruiz
Copy link

e-ruiz commented Aug 1, 2023

@frakman1

This is the trick --format with \t on docker container ls and grab that on awk with -F '\t'

docker container ls --no-trunc -a --format='"{{.Names}}"\t"{{.Image}}"\t"{{.Ports}}"\t"{{.Status}}"' | awk -F '\t' '{$1=$1}1' OFS=","

Note that quoted values provided from --format, good to avoid undesired fields split.

Of course a better way is without awk, in this case a simple:

docker container ls --no-trunc -a --format='"{{.Names}}","{{.Image}}","{{.Ports}}","{{.Status}}"'

References:
https://docs.docker.com/engine/reference/commandline/ps/#format
https://stackoverflow.com/questions/5374239/tab-separated-values-in-awk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment