Docker Compose Support for Pure L1/L2 Networking: A Mini Internet Project
In this article, we will discuss a hobby project focused on building a "mini internet" using Docker Compose and pure L1/L2 networking. The goal is to create a self-contained network of hosts, routers, DHCP, DNS, and TLS services that can be run locally for testing and experimentation.
Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define a YAML file, called docker-compose.yml, which specifies the services, networks, and volumes needed for your application. This file can then be used to start, stop, and manage the services that make up your application.
version: "3.9"
services:
router:
image: router
networks:
- network
host1:
image: host
networks:
- network
host2:
image: host
networks:
- network
dhcp:
image: dhcp
networks:
- network
dns:
image: dns
networks:
- network
tls:
image: tls
networks:
- network
networks:
network:
driver: bridge
Pure L1/L2 Networking
Pure L1/L2 networking refers to a network that operates at the physical (L1) and data link (L2) layers of the OSI model. This means that the network is built using switches, cables, and other physical components, but does not include any routing or higher-level protocols. This type of network is often used in data centers and other environments where high performance and low latency are critical.
In the context of our mini internet project, pure L1/L2 networking allows us to create a self-contained network that can be run locally, without the need for external routing or other network services. This makes it easy to test and experiment with different configurations and setups.
Hosts, Routers, DHCP, DNS, and TLS
The mini internet project includes the following components:
- Hosts: These are the endpoints on the network, such as servers, clients, and other devices. In our project, we will use Docker containers as the hosts.
- Routers: These are the devices that connect different networks together. In our project, we will use a simple L2 switch as the router.
- DHCP: The Dynamic Host Configuration Protocol (DHCP) is a network protocol used to dynamically assign IP addresses to devices on a network. In our project, we will use a Docker container running a DHCP server to provide IP addresses to the hosts.
- DNS: The Domain Name System (DNS) is a hierarchical naming system used to translate domain names to IP addresses. In our project, we will use a Docker container running a DNS server to provide name resolution for the hosts.
- TLS: Transport Layer Security (TLS) is a cryptographic protocol used to provide secure communication over a network. In our project, we will use a Docker container running a TLS server to provide secure communication between the hosts.
Building the Mini Internet
To build the mini internet, we will use Docker Compose to define and run the services, networks, and volumes needed for the project. The docker-compose.yml file will define the router, hosts, DHCP, DNS, and TLS services, as well as the network that connects them together.
version: "3.9"
services:
router:
image: router
networks:
- network
host1:
image: host
networks:
- network
host2:
image: host
networks:
- network
dhcp:
image: dhcp
networks:
- network
dns:
image: dns
networks:
- network
tls:
image: tls
networks:
- network
networks:
network:
driver: bridge
Once the docker-compose.yml file is created, you can use the following command to start the services:
$ docker-compose up -d
This will start the services in detached mode, meaning that they will run in the background.
Testing the Mini Internet
To test the mini internet, you can use the following commands to access the hosts and services:
$ docker-compose exec host1 ping router
$ docker-compose exec host2 ping dns
$ docker-compose exec host1 nslookup host2.local
$ docker-compose exec host1 openssl s\_client -connect tls:443
References
- Docker Compose
- OSI Model: Layer 1
- OSI Model: Layer 2
- Dynamic Host Configuration Protocol (DHCP)
- Domain Name System (DNS)
- Transport Layer Security (TLS)
--endarticle--