LoginSignup
6
2

More than 1 year has passed since last update.

Docker Desktopをv3.5.x~にバージョンアップすると、Remote-Containersでリモートホスト上のコンテナに接続できなくなる問題の対処法

Last updated at Posted at 2021-07-02

問題の概要

  
Docker for Macのバージョンを3.4.0 -> 3.5.1に上げると、リモートサーバー上のコンテナにRemote-Containersで接続できなくなった。

その際のエラー内容は以下。

Error response from daemon: Mounts denied:
The path {$リモートホストでコンテナにマウントしようとしているディレクトリのパス} is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.

リモートホストに接続しているはずなのに、なぜかローカル(Mac)上のDocker Desktopのエラーが発生している。

環境

諸事情でリモートホスト上(EC2)に開発用コンテナを立てており、VSCodeのRemote-Containers拡張機能でコンテナにssh接続して開発していた。図としてはざっくり以下のような感じ。

スクリーンショット 2021-07-03 0.47.24.png

リモートサーバーのDocker Daemonを使用するため、DOCKER_HOST環境変数でリモートのURLを指定していた。

.vscode/settings.json
{
  "docker.host": リモートサーバーのSSH Protocol URL
}

解決策

Docker Desktopのバージョンアップによって変更されたデフォルトのdocker CLI contextをdesktop-linuxからdefaultに戻すことで対処できる。

$ docker context use default

原因

2021-06-23にリリースされたDocker Desktop v3.5.0にて、デフォルトのdocker CLI contextがdefaultからdesktop-linuxへ変更になっていた。そのため、環境変数DOCKER_HOSTでの動的な値の上書きができず、リモートのDocker Daemonにアクセスできなくなってしまっていた。

docker contextとは何かというと、普段dockerコマンドなどで使用しているDocker CLIがDocker Daemonとやりとりするために使用するUNIXソケットなどの情報を、ひとまとまりとして定義できるものらしい(ビルドコンテキストとは名前が似ているがまた別物)。

Docker Desktop(version < 3.4.0)のデフォルトのdocker CLI contextだったdefault contextは、

メモ: デフォルトのコンテキストは、手動で生成したコンテキストとは、多少違った動きをします。 デフォルトのコンテキストには、設定ファイルmeta.jsonが存在しません。 そしてその時点の設定に基づいて、動的に設定が更新されます。

とあり、環境変数DOCKER_HOSTで設定した値によって上書き出来ていたのだが、バージョンアップによりデフォルトのcontextがdesktop-linuxになったことにより、設定ができなくなったと思われる。

解決までの経緯

Remote-Containerのエラーログには、

Error response from daemon: Mounts denied:
The path {$リモートホストでコンテナにマウントしようとしているディレクトリのパス} is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.
Use File sharing to allow local directories on the Mac to be shared with Linux containers.
This is especially useful for editing source code in an IDE on the host while running and testing the code in a container.
By default the /Users, /Volume, /private, /tmp and /var/folders directory are shared.
If your project is outside this directory then it must be added to the list.
Otherwise you may get Mounts denied or cannot start service errors at runtime.

という、「{$リモートホストのディレクトリパス}をコンテナにマウントしようとしているけど、そんなパスはDocker for Macのfile sharing設定で許可しているパスに存在しないよ」という旨が出力されていた。

  1. リモートホストではなくて何故ローカルのDocker for Macのエラーが出ているんだ?という疑問
  2. バージョンアップ前までは動いていたので、リリースノートを確認
  3. デフォルトのdocker contextが変わっており、リモートのDocker Daemonに接続できていなかったことが発覚

という流れだった。


間違い、アドバイス等ありましたら教えていただけますと幸いです。

参考資料

6
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
6
2