Docker provides several network modes for container communication.
Default Bridge Network
Containers on the default bridge network can communicate via IP but not by name.
Custom Bridge Network (Recommended)
# Create network\ndocker network create mynetwork\n\n# Run containers on the network\ndocker run -d --name web --network mynetwork nginx\ndocker run -d --name db --network mynetwork mysql:8\n\n# Containers can reach each other by name\ndocker exec web ping dbDocker Compose
Docker Compose automatically creates a network for all services in the compose file. Services can reach each other by service name.
Host Network
docker run --network host myappContainer shares the host's network directly. No port mapping needed.