Understanding HTTP Communication Without Exposed Ports

Listen to this Post

HTTP is not an executable program or an application; it is a specification that defines how a client and server communicate. This means you can use the HTTP specification without exposing any ports via different mediums on the transport layer, instead of the commonly used TCP and UDP. One example of such a medium is Unix sockets.

By default, the Docker Daemon communicates over a Unix socket using HTTP as the communication format without exposing any ports. This is a nuance that even network engineers sometimes struggle to understand.

To put it simply, HTTP is like a language (e.g., English) with its own set of rules, while TCP/IP or Unix sockets are the mediums through which the message (structured according to the language) is transmitted—whether on paper, by voice, or via sign language.

Practical Examples and Commands

1. Using Unix Sockets with Docker:

  • By default, Docker uses a Unix socket located at /var/run/docker.sock. You can interact with the Docker Daemon using this socket without exposing any ports.
  • Example command to list Docker containers using the Unix socket:
    curl --unix-socket /var/run/docker.sock http://localhost/containers/json
    

2. Creating a Simple HTTP Server Using Python: