Communication
alias #Networking in #Docker
Docker Communication
#Docker_Network #Communication #Network
Its good to have separate environments for different application, but how does these containers talk to each other
Now Docker by default wont creates a network in which these containers do live in.
But each container is assigned an IP address by default by docker we have to create new network using the ==docker network== command and use ==--network== flag in #docker_run command to set the container to run in that specified network.
Docker automatically assigns IP address to the container
For communication between containers you can mention the IP address of the containers in the URL request/response in the source code
Now for communication there are three possibilities
Container to Container Communication [#Docker_CCC]
If the containers are placed in the same network then we can communicate via replacing the IP address of the container by the container ID
If the containers are not in the same network then there is no other option than to communicate based on the IP address of each containers
Container to Outside Websites Communication [#Docker_COWC]
By default docker allows this type of communication
This means that if we want data from swapi.com we can get it using its api
Container to local system Communication [#Docker_CLSC]
for this you need to replace the #IP_Address of local machine to "host.docker.internal"
This lets docker know that there is communication between the container and the local machine
Docker does all the behind the scenes stuff to figure out the connection between local system and container
#Important_Docker
Docker will not change/replace any section in the source code.
Since docker owns the environment, it simply detects the outgoing and incoming requests and resolves the #IP_Address of each request and response as such considering the names and other configurations of the containers(if any specified)
Docker Network Drivers
-> Docker networks actually support different kinds of #drivers_docker which influence the behavior of the network
-> The default driver is the "bridge" driver - it provides the behavior as mentioned [above](#Docker Communication)
-> We can specify the driver when a network is created by simply adding the ==--driver== flag in #docker_command
Alternative Drivers
host
Overlay
macvlan
you can set ==custom mac address== to a container This address can be then used for container communications
none
=> Networking is disabled
==Container Networking Model==
Last updated