LoginSignup
13
14

More than 5 years have passed since last update.

Docker コンテナに一発で .dev ドメインを割り当てるやつ書いた

Last updated at Posted at 2014-10-29

Boot2docker で Docker コンテナにアクセスするとき毎回ポートフォワーディング設定して localhost:12345 とかでアクセスするのめんどくさい、すぐ container-name.dev でアクセスできたら便利だな、と思ったのでそういうのを書いた。 Pow に依存するので Mac 専用。

uasi/boot2docker-powify · GitHub

まず適当な名前でコンテナを実行する(ここでは loving_galileo):

$ docker ps
CONTAINER ID        IMAGE                     COMMAND               CREATED             STATUS              PORTS                    NAMES
e4e983e368f5        dockerfile/ghost:latest   "bash /ghost-start"   3 hours ago         Up 3 hours          0.0.0.0:2368->2368/tcp   loving_galileo

boot2docker-powify を実行すると loving-galileo.dev でコンテナにアクセスできるようになる:

$ boot2docker-powify
Created /Users/uasi/Library/Application Support/Pow/Hosts/loving-galileo
Started forwarding port 2368
======> http://loving-galileo.dev is live

$ curl -s http://loving-galileo.dev | grep "<title>"
    <title>Ghost</title>

割り当てを解除するには boot2docker-depowify を実行する:

$ boot2docker-depowify
Removed /Users/uasi/Library/Application Support/Pow/Hosts/loving-galileo
Killed ssh with pid 16719
Stopped forwarding port 2368
======> http://loving-galileo.dev has gone

$ curl -s http://loving-galileo.dev | grep "<title>"
  <title>Application not found</title>
# ↑これは Pow のプロキシからのレスポンス
13
14
2

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
13
14