docker images
コマンドの結果から、イメージ名だけを抽出し、ダブルクォーテーションでかこったリストを作るワンライナーです。
$ sudo docker images | cut -d' ' -f1 | tail -n +2 | sort | uniq | xargs -L1 -I{} echo '"'{}'"'
"clue/httpie"
"mysql"
"phusion/baseimage"
"selenium/hub"
"shouldbee/ansible-boto"
"shouldbee/baseimage-go"
"shouldbee/flyway"
"shouldbee/go"
"shouldbee/html2pdf"
"shouldbee/nginx-https-reverse-proxy"
"shouldbee/phantomjs"
"shouldbee/php"
"shouldbee/scala"
"shouldbee/selenium-node-chrome"
"shouldbee/selenium-node-firefox"
"shouldbee/tcpproxy"
"sylvainlasnier/memcached"
"ubuntu"
各コマンドの説明
-
sudo docker images
: Dockerのイメージ一覧を取得するコマンドです。イメージ名だけでなくタグ名など他の情報も出ます。
出力例
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
mysql 5.7 804442d17d6a 8 days ago 321.7 MB
mysql 5.7.7-rc 804442d17d6a 8 days ago 321.7 MB
mysql 5.7.7 804442d17d6a 8 days ago 321.7 MB
mysql 5.6 56f320bd6adc 8 days ago 282.9 MB
...
-
cut -d' ' -f1
: 1列目だけを抜き出すコマンドです。-dはデリミタにスペースを指定、-fでは1列目を指定しています。
出力例
$ sudo docker images | cut -d' ' -f1
REPOSITORY
mysql
mysql
mysql
mysql
mysql
mysql
mysql
mysql
mysql
-
tail -n +2
: 2行目以降に絞り込みます。つまり1行目(ヘッダ行)を取り除きます。 -
sort
: イメージ名をアルファベット順にソートします。 -
uniq
: イメージ名で重複している行を取り除きます。 -
xargs -L1 -I{} echo '"'{}'"'
: 各行について、ダブルクォーテーションでくくる処理です。-L1
は1行おきにコマンドを実行するオプション、-I{}
は変数のプレースホルダの定義、echo
以降は各行に実行するコマンドです。