What Is .sock

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 11, 2026

Quick Answer: A .sock file is a Unix domain socket, a special file used for inter-process communication (IPC) on Unix-like systems since the 4.2BSD release in 1983. These sockets enable local process-to-process communication approximately 25-50% faster than TCP sockets by eliminating network protocol overhead. They are essential infrastructure for Docker, databases like PostgreSQL and MySQL, web servers, and system services like systemd.

Key Facts

Overview

A .sock file, formally known as a Unix domain socket, is a special type of socket used for inter-process communication (IPC) on Unix-like operating systems including Linux, macOS, and BSD systems. Unlike traditional network sockets that use TCP/IP protocols and communicate over network interfaces, Unix domain sockets operate entirely within the kernel's file system, allowing processes running on the same machine to exchange data with greater efficiency and lower latency. These socket files typically appear in system directories such as /var/run/, /tmp/, or application-specific directories, and they function as named communication endpoints that enable bidirectional data exchange between processes.

The .sock file format emerged from the 4.2BSD Unix release in 1983 as a fundamental component of Unix interprocess communication standards. Today, they are essential infrastructure for countless modern applications including containerization platforms like Docker, database servers such as MySQL and PostgreSQL, web servers like Nginx and Apache, and system services including D-Bus and systemd. The widespread adoption of Unix domain sockets reflects their superior performance characteristics compared to network-based alternatives, making them the preferred choice for local machine communication in production environments across virtually all Unix-like systems.

How It Works

Unix domain sockets operate through a straightforward mechanism that leverages the file system as a communication endpoint. When a server application creates a .sock file, it establishes a listening socket bound to that file path, effectively opening a communication channel. Client applications can then connect to this socket file by specifying its path, similar to how they would establish network connections. The kernel manages the underlying communication, handling data transfer between connected processes transparently.

Key Comparisons

Understanding how Unix domain sockets compare to alternative communication methods helps explain their widespread adoption in modern systems and development practices.

CharacteristicUnix Domain SocketsTCP/IP SocketsNamed Pipes (FIFO)
Communication ScopeSame machine onlySame machine or networkSame machine only
Performance25-50% faster for local operationsHigher latency due to network stack overheadSimilar performance to .sock but less flexible
Port ManagementNo port allocation requiredRequires explicit port binding and managementNo port concept applies
Security ModelFile system permissions and peer credentialsNetwork firewall rules and application-level authFile system permissions only
Common Use CasesDocker, databases, system services, cachingWeb services, distributed systems, microservicesLegacy IPC, simple inter-process pipelines

Why It Matters

Unix domain sockets represent a critical but often overlooked component of modern system architecture. Their superior performance, simpler security model, and file system integration make them the standard choice for local inter-process communication across virtually all Unix-like systems. Whether you're managing Docker containers, developing database applications, or administering system services, understanding .sock files and their operational characteristics is essential for building efficient, secure, and maintainable systems. As containerization and microservices architectures continue to dominate software development, the importance of Unix domain sockets will only continue to grow.

Sources

  1. Linux man-pages: Unix domain socketsGPL-2.0
  2. Docker Documentation: Configure the Docker daemonApache-2.0
  3. PostgreSQL Documentation: Database Connection ControlPostgreSQL

Missing an answer?

Suggest a question and we'll generate an answer for it.