LoginSignup
1
2

More than 3 years have passed since last update.

port forwardingをunix domain socketにbindすると捗る

Last updated at Posted at 2020-08-12

port forwardingをunix domain socketにbindすると、dockerコンテナ内にvolume mountを通じて持っていけるので便利。
以下、mysqlを例にする。

コマンド

ssh -o StreamLocalBindUnlink=yes -fNL /tmp/sock/db.sock:$DB_HOST:3306 bastion

bastionはもちろん、踏み台サーバー
fNオプションは不要であれば外して良い。
-o StreamLocalBindUnlink=yes をつけると、指定したpathにunix domain socketが既に存在する場合でも上書きしてforwardingしてくれる。

dockerコンテナ内での使用

--volume /tmp/sock:/tmp/sock 付きでコンテナを起動する。

mysql --socket /tmp/sock/db.sock -u ...

curlでも使える

https://qiita.com/toritori0318/items/193df8f749a9c4bda883
ブラウザからアクセスできないのが残念(コンテナ内でブラウザを使うわけではないが、portにbindするのとunix domain socketにbindするのを切り替えるのが面倒くさい)

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2