コンテナにnsenterしてss -tpnをステキに表示

# 結論

```
$ docker inspect -f '{{.State.Pid}}' <ssを実行したいコンテナの名前かID>
12345 <- そのコンテナのPIDが表示される

$ docker run -it --rm --privileged --pid=host debian nsenter -t <上記で取得したPID> -m -u -n -i bash
```

```
root@2a403fe42474:/# ss -tpn | cat
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port
ESTAB      0      0                172.19.0.6:57376           172.19.0.5:5432   users:(("gunicorn",328,12))
ESTAB      0      0                172.19.0.6:45504           172.19.0.3:5672   users:(("gunicorn",216,16))
ESTAB      0      0                172.19.0.6:57968           172.19.0.4:27017  users:(("st2notifier",48,7))
ESTAB      0      0                172.19.0.6:45528           172.19.0.3:5672   users:(("st2actionrunner",92,9))
ESTAB      0      0                172.19.0.6:50750           172.19.0.2:6379   users:(("st2notifier",48,10))
ESTAB      0      0                172.19.0.6:57974           172.19.0.4:27017  users:(("st2actionrunner",92,6))
ESTAB      0      0                172.19.0.6:57970           172.19.0.4:27017  users:(("gunicorn",214,13))
ESTAB      0      0                172.19.0.6:57976           172.19.0.4:27017  users:(("st2actionrunner",100,6))
ESTAB      0      0                172.19.0.6:58070           172.19.0.4:27017  users:(("gunicorn",216,21))
ESTAB      0      0                172.19.0.6:57952           172.19.0.4:27017  users:(("gunicorn",216,13))
ESTAB      0      0                172.19.0.6:45508           172.19.0.3:5672   users:(("st2resultstrack",45,9))
ESTAB      0      0                172.19.0.6:57366           172.19.0.5:5432   users:(("mistral-server",294,4))
ESTAB      0      0                172.19.0.6:57978           172.19.0.4:27017  users:(("st2actionrunner",92,7))
ESTAB      0      0                172.19.0.6:45544           172.19.0.3:5672   users:(("gunicorn",216,18))
ESTAB      0      0                172.19.0.6:58080           172.19.0.4:27017  users:(("python",348,8))
ESTAB      0      0                172.19.0.6:45526           172.19.0.3:5672   users:(("st2actionrunner",92,10))
ESTAB      0      0                172.19.0.6:57966           172.19.0.4:27017  users:(("st2notifier",48,6))
ESTAB      0      0                172.19.0.6:45532           172.19.0.3:5672   users:(("st2actionrunner",100,10))
ESTAB      0      0                172.19.0.6:57986           172.19.0.4:27017  users:(("st2rulesengine",51,6))
ESTAB      0      0                172.19.0.6:57954           172.19.0.4:27017  users:(("gunicorn",202,13))
ESTAB      0      0                172.19.0.6:45496           172.19.0.3:5672   users:(("mistral-server",294,7))
ESTAB      0      0                172.19.0.6:57960           172.19.0.4:27017  users:(("st2garbagecolle",40,6))
ESTAB      0      0                172.19.0.6:57964           172.19.0.4:27017  users:(("st2garbagecolle",40,7))
ESTAB      0      0                172.19.0.6:45548           172.19.0.3:5672   users:(("gunicorn",216,23))
ESTAB      0      0                172.19.0.6:57944           172.19.0.4:27017  users:(("st2sensorcontai",39,6))
ESTAB      0      0                172.19.0.6:57956           172.19.0.4:27017  users:(("gunicorn",202,14))
ESTAB      0      0                172.19.0.6:57950           172.19.0.4:27017  users:(("st2resultstrack",45,7))
ESTAB      0      0                172.19.0.6:57972           172.19.0.4:27017  users:(("gunicorn",214,14))
ESTAB      0      0                172.19.0.6:57988           172.19.0.4:27017  users:(("st2rulesengine",51,7))
ESTAB      0      0                172.19.0.6:45540           172.19.0.3:5672   users:(("st2sensorcontai",39,10))
ESTAB      0      0                172.19.0.6:57948           172.19.0.4:27017  users:(("st2resultstrack",45,6))
ESTAB      0      0                172.19.0.6:45530           172.19.0.3:5672   users:(("st2actionrunner",100,9))
ESTAB      0      0                172.19.0.6:45514           172.19.0.3:5672   users:(("st2notifier",48,9))
ESTAB      0      0                172.19.0.6:45492           172.19.0.3:5672   users:(("mistral-server",294,5))
ESTAB      0      0                172.19.0.6:57946           172.19.0.4:27017  users:(("st2sensorcontai",39,7))
ESTAB      0      0                172.19.0.6:50780           172.19.0.2:6379   users:(("gunicorn",216,22))
ESTAB      0      0                172.19.0.6:45564           172.19.0.3:5672   users:(("st2actionrunner",92,11))
ESTAB      0      0                172.19.0.6:45494           172.19.0.3:5672   users:(("mistral-server",294,6))
ESTAB      0      0                172.19.0.6:45536           172.19.0.3:5672   users:(("st2rulesengine",51,9))
ESTAB      0      0                172.19.0.6:57980           172.19.0.4:27017  users:(("st2actionrunner",100,7))
ESTAB      0      0                172.19.0.6:45490           172.19.0.3:5672   users:(("st2sensorcontai",39,9))
ESTAB      0      0                172.19.0.6:45594           172.19.0.3:5672   users:(("st2notifier",48,12))
ESTAB      0      0                172.19.0.6:45554           172.19.0.3:5672   users:(("python",348,14))
ESTAB      0      0                172.19.0.6:45538           172.19.0.3:5672   users:(("st2rulesengine",51,10))
ESTAB      0      0                172.19.0.6:57362           172.19.0.5:5432   users:(("gunicorn",327,11))
ESTAB      0      0                172.19.0.6:58078           172.19.0.4:27017  users:(("python",348,7))
ESTAB      0      0                172.19.0.6:57958           172.19.0.4:27017  users:(("gunicorn",216,14))
```

プロセスのユーザーがちゃんと表示される。

```
# ワンライナー
docker run -it --rm --privileged --pid=host debian nsenter -t $(docker inspect -f '{{.State.Pid}}' <ssを実行したいコンテナの名前かID>) -m -u -n -i bash
```

Docker for Macでも問題なく使える。