Dockerd Command (with examples)
- Linux
- November 5, 2023
Introduction
The dockerd
command is used to start and manage Docker containers. It is a persistent process that runs in the background and handles all the container operations. In this article, we will explore different use cases of the dockerd
command and understand how to use it effectively.
Use Case 1: Run docker daemon
dockerd
Motivation: This command starts the Docker daemon, allowing you to manage and run Docker containers on your system.
Explanation: Running the dockerd
command without any additional arguments starts the Docker daemon with default settings. This means that it will listen to the default UNIX socket (/var/run/docker.sock
) and will use the default log level.
Example Output: The Docker daemon will start running in the background and you will see its logs on the console.
Use Case 2: Run docker daemon and configure sockets
dockerd --host unix://path/to/tmp.sock --host tcp://ip
Motivation: Sometimes, you may want to configure the Docker daemon to listen to specific sockets. For example, you may want to expose the Docker API on a specific TCP port or use a different UNIX socket for communication.
Explanation: The --host
option is used to specify the sockets on which the Docker daemon should listen. In the above example, we are configuring it to listen on a UNIX socket (unix://path/to/tmp.sock
) and a TCP socket (tcp://ip
).
Example Output: The Docker daemon will start running and will listen to the specified UNIX and TCP sockets.
Use Case 3: Run with specific daemon PID file
dockerd --pidfile path/to/pid_file
Motivation: By default, the Docker daemon creates a PID file at a specific location to store its process ID. However, you may want to specify a different location for the PID file.
Explanation: The --pidfile
option is used to specify the path for the daemon’s PID file. In the above example, we are setting it to path/to/pid_file
.
Example Output: The Docker daemon will start running and create a PID file at the specified location.
Use Case 4: Run in debug mode
dockerd --debug
Motivation: Debugging issues with Docker containers can sometimes be challenging. Enabling debug mode allows you to get more detailed logs and diagnose problems more effectively.
Explanation: The --debug
option enables debug mode for the Docker daemon. It increases the verbosity of the logs, providing more detailed information about the container operations.
Example Output: The Docker daemon will start running in debug mode, and you will see detailed logs on the console.
Use Case 5: Run and set a specific log level
dockerd --log-level=debug|info|warn|error|fatal
Motivation: Controlling the log level of the Docker daemon allows you to manage the amount of information displayed in the logs. Setting a specific log level can help you focus on the relevant information and reduce noise in the logs.
Explanation: The --log-level
option is used to specify the desired log level for the Docker daemon. It accepts values like debug
, info
, warn
, error
, and fatal
. In the above example, we are setting it to one of these log levels.
Example Output: The Docker daemon will start running and display logs at the specified log level.
Conclusion
In this article, we explored different use cases of the dockerd
command. We learned how to run the Docker daemon, configure sockets, specify a daemon PID file, enable debug mode, and set a specific log level. Understanding these use cases will help you effectively manage and troubleshoot Docker containers on your system.