Docker Commands
Docker Commands
1. docker run <image>: Creates and starts a new container from an image.
○ Example: docker run nginx
2. docker run -d <image>: Runs a container in detached mode
(in the background).
○ Example: docker run -d nginx
3. docker run -it <image>: Runs a container interactively with a terminal.
○ Example: docker run -it ubuntu bash
4. docker ps: Lists all running containers.
○ Example: docker ps
5. docker ps -a: Lists all containers, including stopped ones.
○ Example: docker ps -a
6. docker stop <container>: Stops a running container.
○ Example: docker stop my_container
7. docker start <container>: Starts a stopped container.
○ Example: docker start my_container
8. docker restart <container>: Restarts a container.
○ Example: docker restart my_container
9. docker rm <container>: Deletes a stopped container.
○ Example: docker rm my_container
10.docker exec -it <container> <command>: Executes a command
in a running container.
○ Example: docker exec -it my_container bash
11.docker logs <container>: Displays logs from a container.
○ Example: docker logs my_container
12.docker attach <container>: Attaches to a running container's console.
○ Example: docker attach my_container
13.docker kill <container>: Forcefully stops a container.
○ Example: docker kill my_container
Dockerfile Commands
Other Commands
These Docker commands cover the most common activities when working with
Docker, ranging from managing containers, images, and volumes to
orchestrating multi-container applications with Docker Compose. Mastering
these commands helps in efficiently creating, deploying, and managing
containerized applications.