DEV Community

pirvanm
pirvanm

Posted on

100 Days of Servers Distributions- Day 5: Network Layers and Protocols – Understanding the Foundation of Network Communication

What Are Network Layers?
In networking, network layers refer to the structured levels that organize how data travels from one point to another across a network. Each layer has a specific function and works in concert with other layers to ensure successful communication.

The most common framework to understand network layers is the OSI Model (Open Systems Interconnection), which breaks networking into seven distinct layers. Each of these layers handles specific tasks related to network communication, starting from the physical transmission of data up to the application that uses the data.

Here’s a quick overview of the 7 Layers of the OSI Model:

Physical Layer: This is the lowest layer and is responsible for the transmission of raw bitstreams (binary data) over a physical medium like cables or wireless signals.

Data Link Layer: It establishes and terminates connections between physically connected nodes. It also handles error detection and correction to ensure data integrity over the physical layer.

Network Layer: This layer determines the best physical path for data to travel, which is crucial in routing. IP (Internet Protocol) is a well-known example of a network layer protocol.

Transport Layer: It ensures reliable data transfer between systems, managing flow control, error recovery, and data segmentation. TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are key protocols here.

Session Layer: This layer establishes, manages, and terminates communication sessions. It is responsible for maintaining sessions between devices for the duration of their connection.

Presentation Layer: It acts as the translator for the network, ensuring that data is in a usable format for the application layer. It deals with data encryption, compression, and encoding.

Application Layer: The top layer, which interacts directly with the end-user. This layer encompasses protocols used for specific applications such as HTTP for web browsing, SMTP for email, and FTP for file transfer.

How Network Layers and Protocols Work Together
When data is sent over a network, it doesn’t just jump from one device to another. It undergoes a series of transformations as it moves through each network layer, a process known as encapsulation.

Image description

Imagine sending an email:

At the Application Layer, the email is created.
The Presentation Layer converts the data into a format that the network can understand.
The Transport Layer breaks the email into smaller pieces, called segments, and ensures it can be reassembled correctly.
The Network Layer adds addressing information so the email can be routed to its destination.
The Data Link Layer adds error-checking information and prepares the data for transmission.
Finally, the Physical Layer converts the data into electrical, radio, or optical signals that are sent through the network.
When the email reaches its destination, the layers on the receiving device reverse the process to reconstruct the email.

Who we can dockerize ?

Docker Compose (Optional)
If you want to add more services (e.g., a database or caching layer), you could use Docker Compose. Here’s a basic docker-compose.yml file for running the app alone:

docker-compose.yml

version: '3'
services:
  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/app
    environment:
      - NODE_ENV=development
Enter fullscreen mode Exit fullscreen mode

Building and Running the Dockerized App
Step 1: Build the Docker Image
To build the Docker image for the application, run the following command from the project directory:

docker build -t network-layers-app .
Enter fullscreen mode Exit fullscreen mode

This command tells Docker to build an image with the name network-layers-app based on the Dockerfile.

Step 2: Run the Docker Container
Once the image is built, you can run the app in a Docker container using the following command:

docker run -p 3000:3000 network-layers-app
This binds port 3000 on your host machine to port 3000 inside the container, allowing you to access the app in your browser by visiting http://localhost:3000.
Enter fullscreen mode Exit fullscreen mode

For more course click here

Top comments (0)