Domain redirect for local development

I’m sure many of you know how to do this …I’m new to docker development.

I am planning to use Docker for wordpress development on my local Ubuntu box. I want to do the development in the container and then be able to browse to the site from a browser on my Host Computer.

In other words, if the domain for my wordpress site is http://www.nicehats.com, I want to be able to type http://www.nicehats.com in my browser and have it redirected to the (guest) site in the docker container (on my local ubuntu box) rather than to the site located out on a public server. What is the cleanest or most straightforward way to do this?

I’m assuming it just takes a line or two in /etc/hosts. Hopefully I’ll still be able to browse to other websites without changing my /etc/hosts (ie: obviously, I don’t want to redirect everything to the container).

Thanks in advance for the help.

Very surprised - actually shocked - that there has been no reply to this question after an entire week!

I have figured out a solution to this problem …but it’s a solution that doesn’t absolutely require a docker container although I’m sure it would work in a docker container. The answer, briefly is that to get this to work, three things are needed:

  1. A line in the /etc/hosts file containing: <local public IPv4 address> nicehats.com
    ,…and a second line for the “www” version of the domain.
  2. An Apache Virtual Host on the system for nicehats.com
  3. The “hosts” line in nsswitch.conf must show the correct order if the domain is a valid domain already existing on the internet (present on a dns server); ie “files” must appear before “dns” …like this: “hosts: files dns” . After this it will be necessary to restart nscd and network manager.
  4. Finally, it is necessary to check the Name Service Caching Daemon and ping the URL with and without the “www” to make sure both versions resolve to the correct IP address.

As previously mentioned this solution is not Docker-specific …it works on a host with apache and MySql installed. There is probably another step or two to get it to work with Docker.