# Networking in Docker Engine # Overview - How does Docker Networks work? [![logo.png](https://wiki.aeoneros.com/uploads/images/gallery/2024-09/scaled-1680-/rfuZed4CizAXYqTM-logo.png)](https://docs.docker.com/engine/network/)Container networking refers to the ability for containers to connect to and communicate with each other, or to non-Docker workloads. Containers have networking enabled by default, and they can make outgoing connections. A container has no information about what kind of network it's attached to, or whether its peers are also Docker workloads or not. A container only sees a network interface with an IP address, a gateway, a routing table, DNS services, and other networking details. That is, unless the container uses the `none` network driver. This page describes networking from the point of view of the container, and the concepts around container networking. It doesn’t cover OS-specific details about how Docker networks work. For more information about how Docker manipulates iptables rules on Linux, see [Packet filtering and firewalls](https://docs.docker.com/network/iptables/). --- ### User-Defined Networks You can create custom, user-defined networks and connect multiple containers to the same network. Once connected, containers can communicate with each other using container IP addresses or container names. ``` docker network create -d bridge my-net docker run --network=my-net -itd --name=container3 busybox ``` --- ### [Drivers](https://wiki.aeoneros.com/books/docker-guide/page/network-drivers-overviewsummery) The following network drivers are available by default and provide core networking functionality:
DriverDescription
`bridge`The default network driver.
`host`Removes network isolation between the container and the Docker host.
`none`Completely isolates a container from the host and other containers.
`overlay`Connects multiple Docker daemons together.
`ipvlan`Provides full control over IPv4 and IPv6 addressing.
`macvlan`Assigns a MAC address to a container.

For more information, take a deepdive into the different Drivers at [this Post](https://wiki.aeoneros.com/books/docker-guide/page/network-driverslist-detailed-explanation).

--- ### Container Networks In addition to user-defined networks, you can attach a container to another container's networking stack directly using the `--network container:` flag format. The following example demonstrates running a Redis container with Redis binding to localhost, then running the redis-cli command and connecting to the Redis server: ``` docker run -d --name redis example/redis --bind 127.0.0.1 docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1 ``` --- ### Published Ports By default, containers on bridge networks don’t expose ports to the outside world. Use the `--publish` or `-p` flag to make a port available externally. Examples:
Flag ValueDescription
`-p 8080:80`Maps port 8080 on the Docker host to TCP port 80 in the container.
`-p 192.168.1.100:8080:80`Maps port 8080 on host IP 192.168.1.100 to TCP port 80 in the container.
`-p 8080:80/udp`Maps UDP port 8080 on the host to UDP port 80 in the container.
**Important:** Publishing container ports is insecure by default. To restrict access, bind ports to `localhost` or specific IP addresses. --- ### IP Address and Hostname Containers receive an IP address for every network they attach to. The Docker daemon dynamically assigns these IPs based on the network’s subnet. You can specify IP addresses manually using the `--ip` or `--ip6` flags. By default, a container’s hostname is its ID. You can override this using `--hostname`. For additional network aliases, use the `--alias` flag when connecting a container to a network. For more details, see the [official documentation](https://docs.docker.com/engine/network/#ip-address-and-hostname). --- ### DNS Services By default, containers inherit DNS settings from the host. You can override these settings using the following flags:
FlagDescription
`--dns`The IP address of a DNS server.
`--dns-search`A DNS search domain for non-fully qualified hostnames.
`--dns-opt`Key-value pairs for DNS options.
For more details, see the [official documentation](https://docs.docker.com/engine/network/#dns-services). # Network Driverslist & Detailed Explanation [https://docs.docker.com/engine/network/drivers/](https://docs.docker.com/engine/network/drivers/) . [https://www.youtube.com/watch?v=bKFMS5C4CG0](https://www.youtube.com/watch?v=bKFMS5C4CG0) # Packet filtering and firewalls [https://docs.docker.com/engine/network/packet-filtering-firewalls/](https://docs.docker.com/engine/network/packet-filtering-firewalls/)