In this article, we will see what is docker.sock and how it works along with examples.
One of the important components of the Docker is the docker.sock. It is a Unix socket that is used by the Docker daemon to communicate with the Docker client. This provides a more secure and efficient way of communication between the Docker client and the Docker daemon.
This is created when the docker daemon starts up and is located at
/var/run/docker.sock on the host machine.
How does docker.sock works?
docker.sock file is used by the Docker client to send commands to the Docker daemon, and receive responses from the Docker daemon. When we run the Docker command, such as
docker run, the Docker client sends the command to the Docker daemon over the
The Docker daemon executes the command inside a container and sends the response back to the Docker client over the
docker.sock file. This allows the user to interact with the Docker daemon and manage Docker containers using the Docker CLI.
Example of using docker.sock
Assume, we have a Docker container running on our local machine, and we want to start a new container and mount a volume to it.
docker run -it -v /my/local/folder:/data my-image:latest
When we run the above command, the Docker client sends the command to the Docker daemon over the
docker.sock file. The Docker daemon then starts a new container using the
my-image Docker image and mount the
/my/local/folder directory to the
/data directory inside the container, and sends the response back to the Docker client over the