sh4 sh4 - 3 months ago 14
PHP Question

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.

Answer

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.

Comments