Docker Community Forums

Share and learn in the Docker community.

Hostnames and ports


(Federicorocchegiani) #1

it is possible to use a hostname different from localhost to point a container?
it is possible, for example, to create a scenario like this?

  • host app1.somthing.local -> point to the container1
  • host app2.somthing.local -> point to the container2
    where the both containers are running an apache server on port 80

in particular i’m talking about docker for mac.


(Fskreuz) #2
  1. Run the containers, binding them to different ports (i.e. container 1 at port 8001, container 2 at port 8002).
  2. Run an nginx container that binds to 80 and configured to forward to the right port depending on the domain. See this StackOverflow answer for an overview.
  3. On your Mac’s hosts file, map both app1.somthing.local and app2.somthing.local to 127.0.0.1, sort of the DNS in the setup.