So whenever you install docker you create 3 default networks :
- Bridge Network
- Null Network
- Host Network
Any container that is started will by default join the Default bridge network.
Let's take an example to explain this.
So i have a nginx container running inside the default bridge network. I'll start up an image of Node and expose it at port 3000 in the dockerfile.
$ docker run -d node
Once the container starts it will be exposed at the port 3000 but only inside the default bridge network, which means that nginx can access this container but only at the port 3000 as they are both in the same network.
If the container needs to be accessed from outside( Host Server ) then it has to mapped to the host server using the -p flag like given below:
$ docker run -p 3000:3000 Node
This allows all communication to the container from the port 3000 on the host server and port 3000 on the container.
Now instead you could use Host Network which does not isolate the container and instead actually makes it so that when you access you Host Server you get access to the container attached to the host network.
for example if the our node container was attached to the Host network. you could access the container at the IP of you host server.
Hope this helps :)
If you are still having a bit of trouble you can always try out docker training courses or check out this docker tutorial.