One of the things I really haven’t mastered is Docker networking. It just isn’t intuitive to me. What I have been able to do though, is have a container use the host address and be accessible to other hosts on the network. For example, if you have Docker installed on a host with an IP address of 192.168.1.25, it is very easy to have the Docker container use that address and be available via the browser on whatever port the container is defaulted to. For example, Dashy is an open source dashboard program that is pretty useful and I think very well done. Dashy uses port 80 and is available via the web browser. In order to install a Docker Dashy container and have it be available using the host address, you need to add an argument to the typical Docker pull for a container, this would make Dashy available via the browser at 192.168.1.25 in my example.
The command to instantiate a Dashy Docker container using host network is as follows:
docker run -d --name=dashy --restart=always --network=host \
-v /opt/dashy/config/conf.yml:/app/public/conf.yml \
lissy93/dashy
The magic part above is the:
--network=host
Without that Docker runs on it’s own network and you have to expose ports and all kinds of other fun stuff and I’ve never had the patience to master. The above works absolutely flawlessly and you can even run multiple web applications via Docker containers on the same host as long as they all use different ports (see my note below). I have Statping-ng (port 8080), Dashy (port 80) and The Lounge IRC Client (port 9000) all running on the same host with no issues at all!
One key point is when you do this, use the host network, you lose the ability to assign a container to a port you specify. Even if you try to do so via the command line using the -p argument, it will be completely ignored when --network=host
argument is invoked.
I have some more Docker tips coming as I have found a few other tidbits which have really helped me stand up some apps very quickly. I will post them all soon!
Thanks,
rob