Updated: Jan 18, 2022
So when you start a new container, you're really in the background connecting to a particular Docker network. By default, each container is connected to a private virtual network "bridge," and then each virtual network routes through NAT firewall on Host IP (Docker demon configuring the IP address as a default interface so the containers in it can get out to the internet).
So now that we have the basic theory, let's start to write some commands starting with the -p to publish its port:
PS C:\> docker container run -p 80:80 --name webhost_2 -d nginx
Note: publishing ports are always in HOST: CONTAINER format.
Now that we've created the new container, let's check the port configuration of this container by running the port command:
docker container port webhost_2
and the result we get is "80/TCP -> 0.0.0.0:80," a friendly and easy format that shows the ports that are forwarding traffic from the host into the container.
Now you may assume that the containers created under the Docker server will get their IP, well that's not true. If we want to check the container IP, we should use the Docker inspect command as follow:
docker container inspect webhost_2