Master the essentials of Docker CLI to create, manage, and troubleshoot containers efficiently. This guide covers key commands, options, and best practices for container operations.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Table of Contents
- Quick Syntax Reference
- Command Syntax Styles
- Creating a Container
- Listing Containers
- Starting a Container
- Create & Start in One Step
- Ephemeral Containers
- Interactive Shells
- Exiting Containers
- Naming Containers
- Detached Mode
- Links and References
Quick Syntax Reference
Use this general pattern for Docker commands:Command Syntax Styles
Docker supports both legacy and grouped syntax. We’ll use the grouped style throughout this guide.| Syntax Type | Example |
|---|---|
| Grouped (new) | docker container run -it ubuntu |
| Legacy (old) | docker run -it ubuntu |
Creating a Container
To create (but not start) a container:/var/lib/docker/:
containers/<container-ID>/.
Listing Containers
Usedocker container ls with options to filter the output:
| Command | Description |
|---|---|
docker container ls | Show running containers |
docker container ls -a | Show all containers (running & stopped) |
docker container ls -l | Show the most recently created container |
docker container ls -q | Display only container IDs (running) |
docker container ls -aq | Display all container IDs |
Starting a Container
Start an existing container by its ID or name:Create & Start in One Step
Pull the image, create, and start the container:Ephemeral Containers
Some images (likeubuntu) don’t run a persistent process:
Interactive Shells
Keep STDIN open and allocate a pseudo-TTY with-it:
Always place options (
-i, -t, -d, --name) before the image name. Anything after the image name is interpreted as the container’s command.Exiting Containers
Runningexit inside an interactive shell stops the container:
Naming Containers
Assign a custom name at creation:Detached Mode
Run containers in the background with-d: