LoginSignup
1

More than 5 years have passed since last update.

【簡易版】Docker Container 上のアプリケーションにスマホからアクセスする

Last updated at Posted at 2018-07-25

やりたいこと

ホスト上で開発しているときは,docker-machine ip dev で得られる IP アドレスで Docker Container 上のアプリケーションにアクセスできる.

例えば,アプリケーションが 8080 ポートを開放している場合は http://192.168.99.100:8080/ でアクセス可能
一方,スマホをホスト PC と同じネットワークに接続し,スマートフォンから http://192.168.1.11:8080 ではアクセスはできない.

Rails の -b オプションみたいなことをやりたい

$ bundle exec rails s -b 192.168.1.11

http:192.168.1.11:3000 で同ネットワーク上のスマホからアクセスできる

前提

  • macOS High Sierra 10.13.5
  • Docker 18.03.1
  • Virtual Box 5.2.12
  • Docker Container 上で Python Bottle を動かしている
python
from bottle import route, run, template, request, static_file, error

@route('/')
def home():
    return template('home')

run(host='0.0.0.0', port=int(os.environ.get("PORT", 8080)))

※ host='localhost' ではなく '0.0.0.0' とする必要がある

VirtualBox 上で Port Forwarding 設定

Settings > Network > Port Forwarding で

image.png

image.png

image.png

http://192.168.1.11:4649 でアクセスができるようになる.

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