0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[DockerToolbox] コンテナのポートに接続できない

Posted at

本記事は Docker Toolbox を対象としています。Docker for Windows は対象外

コンテナに接続できない

Python + Flask でAPIサーバを開発するため、Dockerコンテナ上で4000番ポートに開いた開発サーバに接続したい。Dockerの設定は以下の通り。

docker-compose.yml
version: "3"
services:
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: "backend"
    ports:
      - "4000:4000"
    volumes:
      - "./backend/:/app"
  ...他のサービス...

Dockerコンテナ:ポート4000 <=> Dockerホスト:ポート40000 と繋がっています。

環境

  • Windows 10 Home 64bit
  • Docker version 19.03.1

Windows 10 Home では Hyper-V が使用できないため DockerToolbox 経由でインストール

原因

Linuxカーネルを提供する仮想環境(VirtualBox)が間に挟まっているため、DockerホストはVirtualBoxでありWindows(ホストOS)とは別物。
Dockerコンテナ:4000 <=> Dockerホスト:40000 <=未接続=> Windows:4000 とホストOSまで繋がっていない。
詳しくは [Qiita] Dockerを活用するためのネットワーク関連操作のおさらい が参考になりました。

解決手法

VirtualBox と Windows 間に適切なポートフォワーディングを設定します。

  1. VirtualBox マネージャーを開き、仮想マシンを選択して設定を開く
  1. ネットワーク>高度>ポートフォワーディングを選択
  1. ポートフォワーディングを設定
これで`Dockerコンテナ:4000 <=> Dockerホスト:40000 <=> Windows:4000`と無事に接続できました。
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?