I recently talked with the guys over at SQL Data Partners on their podcast about SQL Server and containers. It was real good fun and I enjoyed chatting with Carlos Chacon (b|t) and Steve Stedman (b|t)about container technology and my experiences with it so far. Would definitely like to go back on (if they’ll have me 🙂 )
Anyway, during the podcast one of the questions that came up was “How do containers interact with the network resources on the host server?”
To be honest, I wasn’t sure. So rather can try and give a half answer I said to the guys that I didn’t know and I’d have to come back to them.
Career Tip – when working with technology it’s always better to say you don’t know but will research and come back with an answer, than it is to try and blag your way through.
Once the podcast recording was over I started to think about it. Now there’s a bit of a clue in the code when you run a container:-
docker run -d -p 15798:1433 --name TestContainer ImageName
The -p 15798:1433 part of the code specifies which port on the host server maps to a port in the container. So there’s a NAT network in there somewhere?
I went off and did a bit of research and I found the following diagram which details how the containers interact with the host at the network layer:-
In essence the container host’s network connectivity is extended to containers via a Hyper-V virtual switch which containers connect to via either the Host virtual NIC (this is for windows server containers) or a synthetic VM NIC (for Hyper-V containers).
The containers themselves can connect to the host network via different modes.The default is a NAT network that is created by the docker engine onto which container endpoints are automatically attached and this allows for port forwarding from the Host to the containers (which we see in the code earlier in this blog).
This can all be seen by running the following commands:-
To list the docker networks:-
docker network ls
To get the network adapters of a server:-
To get the virtual switches of a hyper-v host (remember some hyper-v elements are installed when the container feature is enabled):-
So there’s how it works! Thanks for reading.