Deploying docker and then wordpress, what about DNS ?

June 15, 2017 566 views
DNS Docker WordPress Ubuntu

Hi,

So i found some tutorials for deploying docker to ubuntu - actually there is already a one click app for creating a docker image. Once this is done, I have found a tutorial for deploying mariadb and wordpress to the container. Although I am confused about dns ?

Do I need to configure DNS, via nginx or something ?

Anyone have any good examples ?

I was thinking of using an external DNS service. or do you have recommendations, I really dont want to have my own dns server.

Thanks in advance.

1 comment
  • I know there is also a 1 click app for wordpress, but I wanted to take advantage of docker rather than a direct instal..

1 Answer

@ianjohnspain

Since Docker would be using internal IP addresses, you'd need to proxy incoming requests using NGINX (for example) to the Docker container. You'd simply point an A entry for the domain to the IP of your main Droplet IPv4 IP.

For example, your main IPv4 IP might be 104.112.113.45 and the internal IP for the container may be 10.20.11.15. In such a case, NGINX would accept incoming requests on the IPv4 IP for the Droplet, proxy them to the container IP and the container would handle the request from there.

NGINX (on the Droplet) would be setup to listen on port 80 while the container may be setup to listen on any port that you wish (such as port 8080). The only important step there would be to make sure that NGINX (on the Droplet) is setup to proxy to the correct port on the container.

Your DNS, in such a case, is no different than any other type of setup. You'll still set the A entry for the domain to the IP of the Droplet and create your www CNAME to match, should you need it.

  • THanks for the reply. Probably a stupid question, but could I also run nginx inside the container ? I presume so right ? I was hoping to have 1 droplet (with docker)

    • @ianjohnspain

      You'd end up running two instances of NGINX -- one running on the main Droplet and one running within the container.

      The reason for this is because Docker doesn't use public IP addresses, thus it doesn't bind to your main Droplet IP (whether IPv4 or IPv6) -- instead it uses local IP's, similar to private networking IP's.

      You'd use the instance of NGINX that's on the main Droplet to proxy incoming request on ports 80/443 to ports that you've opened on the container for the same purpose. You can bind to the same ports (many do), though you can also use alternative ports.

      What you end up with is something such as this:

      Incoming Request (Port 80) => Droplet (NGINX/Docker) => Container (LEMP Stack/WordPress)
      

      The NGINX instance on the Droplet accepts the incoming request, proxies it to the container which is the full stack and WordPress installation, and then it functions as it normally would as if you were running it at just the hypervisor level (i.e. without Docker).

      For something such as a simple WordPress site, you may actually be better of going without Docker unless you really plan on integrating Docker in to your entire work flow. There's a good bit of detail and caution that's needed with Docker.

      For instance, without setting up volumes, if you bring the container down or destroy it, your data is gone with it. Generally once a container is setup, you run with it and when you need to update something such as NGINX, PHP, or MariaDB, you bring it down and then spin up a new container with the required software, then destroy the other.

      If you don't use volumes, the above is going to be a nightmare as you'll end up losing data.

Have another answer? Share your knowledge.