sh4
sh4

Reputation: 1265

Map docker container to regular dev domain name

I'm new to docker, and have recently installed a docker container/image using the phpdocker.io (php7, nginx, mysql) generator. Started it using docker-compose and it's working awesome.

If I go to localhost/phpinfo.php my regular system php version loads (5.6), if I go to localhost:8080/phpinfo.php my docker php version loads (7.0) so it's working ok.

My question is: There is any way to map my localhost:8080 to a regular domain name like I normally do with my regular localhost projects? Withouth having to use localhost:8080 i.e.: myproject.dev

Not sure if this is specifically docker related or not.

Upvotes: 4

Views: 1319

Answers (2)

NabLa
NabLa

Reputation: 108

Just as a side note, the nginx conf on projects generated by phpdocker.io will respond to any hostname, so you simply need to add the relevant entry on the hosts file.

Upvotes: 1

Bukharov Sergey
Bukharov Sergey

Reputation: 10185

it is easy. if your nginx config looks like this:

server {
   server_name _; #catch all
   ...

you can add to hosts file on you host machine the line

127.0.0.1 myproject.dev

and your container will be available by url http://myproject.dev:<exposed_port>

if you expose you container on 80 port, you can simply type url http://myproject.dev (like the good old days). But remeber you can run only one container on 80 port at the same time.

Upvotes: 4

Related Questions