docker image prune

表題のコマンドを試す。

■ 環境

  • Docker for Mac 1.13.0
  • Mac OSX El Capitan

■ image prune

打ち間違えをしたような気がして表示されたヘルプを見ていたら気になった”prune“サブコマンド。

$ docker image

Usage:     docker image COMMAND

Manage images

Options:
      --help   Print usage

Commands:
  build       Build an image from a Dockerfile
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Display detailed information on one or more images
  load        Load an image from a tar archive or STDIN
  ls          List images
  prune       Remove unused images
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rm          Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

Run 'docker image COMMAND --help' for more information on a command.
$

使っていないイメージを削除してくれるようである。さらにヘルプを見てみる。

$ docker image prune --help

Usage:     docker image prune [OPTIONS]

Remove unused images

Options:
  -a, --all     Remove all unused images, not just dangling ones
  -f, --force   Do not prompt for confirmation
      --help    Print usage
$

prune“なんてあったんだ、と嬉しくなって早速試してみることに。今までは不要なコンテナイメージは下記のように削除をしていた。

docker rmi $(docker images -q -f dangling=true)

では早速`prune`サブコマンドを実行してみる。

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
$
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
elasticsearch       latest              3b9ab09f293c        13 days ago         353 MB
elasticsearch       <none>              3429053f4435        3 months ago        344 MB
mysql               latest              cf725f136fd2        3 months ago        383 MB
$
$ docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0 B
$
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
elasticsearch       latest              3b9ab09f293c        13 days ago         353 MB
elasticsearch       <none>              3429053f4435        3 months ago        344 MB
mysql               latest              cf725f136fd2        3 months ago        383 MB
$

Tag“が”none“のコンテナイメージが削除されるのを期待したのだが、そうではないらしい…。”-a”というオプションもあるのでそちらを実行すると、、使われていないコンテナ全てが削除されてた…。イメージと違う動きをしてくれる…。

以上。

■ 関連

Lambda用に`npm deploy`

表題の通り。`npm deploy`コマンドを設定してしまっているというお話。

■ 環境

  • AWS Lambda
  • node v4.4.7
  • Mac OSX El Capitan

■ きっかけ

ServerlessFrameworkとかを使っていない環境で、Lambdaに簡易的にデプロイしたいなと思った時に、”package.json“に1行加えてデプロイをしている。いや、ServerlessFrameworkとかも使ったことすらないけど…。

■ AWS Lambda

各種設定等は”Management Console“で先にやってしまっている。そこでARNを取得する。

AWS Lambda > Functions > Function選択 > Actions > Show ARN

ここで得られた”ARN“を元にコマンドを設定する。

■ pakcage.json

{
  "name": "test",
  "version": "0.0.1",
  "description": "test test test.",
  "main": "index.js",
  "scripts": {
    "zip": "zip -r test.zip index.js node_modules",
    "update": "aws lambda update-function-code --function-name arn:aws:lambda:ap-northeast-1:XXXXXXXXXXX:function:test --zip-file fileb://`pwd`/test.zip --publish",
    "deploy": "npm run zip && npm run update"
  },
  :
}

上記のような”scripts“を追加している。後は実行するだけでOKである。

$ npm run deploy

当初はかなり適当に設定してみたのだが、意外と使えたので最近はもっぱらこれを使用している。

以上。

wall

表題のコマンドを実行する。

■ 環境

  • Linux

■ wall

対象のサーバにログインしている全てのコンソールに対して、メッセージを送りたかったので、そういえばどのコマンドだったっけ?と思ったがすぐに出てきた。

$ wall
hello world

Broadcast Message from ubuntu@paid01
        (/dev/pts/1) at 19:19 ...

hello world

$

オプション無しで実行した後は、標準入力から複数行書くことが可能である。”control-D“で送るメッセージを終了する。

これを受け取った側は下記のようになる。

$

Broadcast Message from ubuntu@paid01
        (/dev/pts/1) at 19:19 ...

hello world


$

サーバを停止させるときとかに使われる。仕事においては基本的にみんな同じ場所にいたりすることが多いし、Slack等での情報共有の方が多いのだが、極稀に必要なときがあるのでメモしておく。

以上。

続vnstat

表題の通り、先日の`vnstat`の続きである。

■ 環境

  • Ubuntu 14.04

■ vnstat

昨日は見ても何も面白い結果が無かったので、一日経過して再度見てみる。

$ vnstat
Database updated: Thu Jan 26 19:11:25 2017

   eth0 since 01/25/17

          rx:  36.83 MiB      tx:  28.28 MiB      total:  65.11 MiB

   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       Jan '17     36.83 MiB |   28.28 MiB |   65.11 MiB |    0.24 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        43 MiB |      33 MiB |      76 MiB |

   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     yesterday     10.02 MiB |    9.87 MiB |   19.89 MiB |    1.89 kbit/s
         today     26.81 MiB |   18.41 MiB |   45.22 MiB |    6.70 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        40 MiB |      28 MiB |      68 MiB |
$

少しだけ見た目が面白くなった。”help“を見てみる。

$ vnstat -h
vnStat 1.11 by Teemu Toivola 

         -q,  --query          query database
         -h,  --hours          show hours
         -d,  --days           show days
         -m,  --months         show months
         -w,  --weeks          show weeks
         -t,  --top10          show top10
         -s,  --short          use short output
         -u,  --update         update database
         -i,  --iface          select interface (default: eth0)
         -?,  --help           short help
         -v,  --version        show version
         -tr, --traffic        calculate traffic
         -ru, --rateunit       swap configured rate unit
         -l,  --live           show transfer rate in real time

See also "--longhelp" for complete options list and "man vnstat".
$

デフォルトでは”monthly“と”daily“だけが見られるようなので他のも見てみる。

$ vnstat -w

eth0  /  weekly

                      rx      |     tx      |    total    |   avg. rate
   ---------------------------+-------------+-------------+---------------
    last 7 days     36.94 MiB |   28.40 MiB |   65.34 MiB |    0.93 kbit/s
   current week     36.94 MiB |   28.40 MiB |   65.34 MiB |    1.70 kbit/s
   ---------------------------+-------------+-------------+---------------
      estimated        69 MiB |      54 MiB |     123 MiB |
$
$ vnstat -m

eth0  /  monthly

       month        rx      |     tx      |    total    |   avg. rate
    ------------------------+-------------+-------------+---------------
      Jan '17     36.94 MiB |   28.40 MiB |   65.34 MiB |    0.24 kbit/s
    ------------------------+-------------+-------------+---------------
    estimated        43 MiB |      33 MiB |      76 MiB |
$
$ vnstat -m -w

eth0  /  weekly

                      rx      |     tx      |    total    |   avg. rate
   ---------------------------+-------------+-------------+---------------
    last 7 days     36.94 MiB |   28.40 MiB |   65.34 MiB |    0.93 kbit/s
   current week     36.94 MiB |   28.40 MiB |   65.34 MiB |    1.70 kbit/s
   ---------------------------+-------------+-------------+---------------
      estimated        69 MiB |      54 MiB |     123 MiB |
$

最後は”-m“と”-w“を両方指定して実行してみたのだが、”-w“の結果しか得られなかった。”-l“でリアルタイムの状態も見られるようである。

以上。

■ 関連

Ubuntuにvnstatをインストール

表題の通り。

■ 環境

  • Ubuntu 14.04

■ vnstat

下記のようにインストールした。

$ sudo apt-get install vnstat

インストール直後は下記のようになった。

$ vnstat
eth0: Not enough data available yet.
$

データベースを作る必要がある?とのことなので下記を実行。

$ sudo vnstat -u -i eth0

これで一旦は結果を得られるようになった。

$ vnstat
Database updated: Wed Jan 25 19:09:41 2017

   eth0 since 01/25/17

          rx:  37 KiB      tx:  39 KiB      total:  76 KiB

   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       Jan '17        37 KiB |      39 KiB |      76 KiB |    0.00 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        --     |      --     |      --     |

   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
         today        37 KiB |      39 KiB |      76 KiB |    0.01 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        --     |      --     |      --     |
$

デーモンで稼働させるらしい。

$ sudo service vnstat start

しばらく放置して確認してみよう。

以上。

■ 関連