Docker originally was used with straightforward, individual commands for each task. Over time, as more features were added, this approach became harder to manage. To make the interface clearer and more structured, Docker introduced an object‑based command system, grouping commands by the type of resource they control. Essential Docker Commands:
Docker Container Run
This is the most fundamental command. It creates a new container from a specified image and then starts it. If the image is not found locally, Docker will automatically try to pull it first.
$ docker container run <image_name>
To give name of container
$ docker container run --name <container_name> <image_name>

Docker Pull
This command allows you to pull any image which is present in the official registry of docker, Docker hub. By default, it pulls the latest image, but you can also mention the version of the image.
$ docker pull <image_name>
Docker PS
This command (by default) shows us a list of all the running containers. We can use various flags with it.
- -a flag: shows us all the containers, stopped or running.
- -l flag: shows us the latest container.
- -q flag: shows only the Id of the containers.
$ docker ps [options..]
Docker Container Stop
This command allows you to stop a container if it has crashed or you want to switch to another one.
$ docker container stop <container_ID>
Docker Container Start
Suppose you want to start the stopped container again, you can do it with the help of this command.
$ docker container start <container_ID>Docker rm
Removes one or more stopped containers. You cannot remove a container that is still running; you must stop it first. You can use the docker stop <container_name or ID> command to stop the container. Some important flags:
- -f flag: remove the container forcefully.
- -v flag: remove the volumes.
- -l flag: remove the specific link mentioned.
$ docker rm {options} <container_name or ID>
Docker RMI
To delete the image in docker. You can delete the images which are useless from the docker local storage so you can free up the space
docker rmi <image ID/ image name>Docker Images
Lists all the pulled images which are present in our system.
$ docker images
Docker exec
This command allows us to run new commands in a running container. This command only works until the container is running, after the container restarts, this command does not restart. Some important flags:
- -d flag: for running the commands in the background.
- -i flag: it will keep STDIN open even when not attached.
- -e flag: sets the environment variables
$ docker exec {options}

Docker Ports (Port Mapping)
In order to access the docker container from the outside world, we have to map the port on our host( Our laptop for example), to the port on the container. This is where port mapping comes into play.
$ docker run -d -p <port_on_host>
<port_on_container> Container_name

So these were the 9 most basic docker commands that every beginner must know. Containerization is a very vast topic but you can start from the very basic commands and by practicing them daily you can master them.
Docker Login
The Docker login command will help you to authenticate with the Docker hub by which you can push and pull your images.
docker login It will ask you to enter the username and password after that you will authenticate with DockerHub and you can perform the tasks.
Docker Push
Once you build your own customized image by using Dockerfile you need to store the image in the remote registry which is DockerHub for that you need to push your image by using the following command.
To know more about How to Push a Container Image to a Docker Repository: Push a Container Image to a Docker Repository
docker push <Image name/Image ID> Docker Build
The docker build command is used to build the docker images with the help of Dockerfile.
docker build -t image_name:tag .In the place of image_name use the name of the image you build with and give the tag number and . "dot" represents the current directory.
Prune Command
This is a powerful command that removes all unused Docker objects in one go. By default, it removes:
- All stopped containers.
- All Build Cache.
- All unused networks.
- All dangling images (images that are not tagged and not used by any container).
docker system prune
Stop Multiple Containers
Instead of stopping a single container. You can stop multiple containers at a time by using the following commands.
docker stop container1 container2 container3Docker Restart
While running the containers in Docker you may face some errors and containers fails to start. You can restart the containers to resolve the containers by using the following commands.
docker restart container_name_or_idDocker Inspection
Docker containers will run into some errors in real time to debug the container's errors you can use the following commands.
docker inspect container_name_or_idDocker Container Top Command
Displays the running processes inside a container. It's like running the top command on Linux, but targeted at a specific container.
docker container top <container_id_or_name>
Docker Commit command
After running the containers by using the current image you can make the updates to the containers by interacting with the containers from that containers you can create an image by using the following commands.
docker commit container_name_or_id new_image_name:tagDocker Logs
The docker logs command is used to view the logs generated by a running or stopped container. It is useful for troubleshooting applications and identifying errors inside containers.
docker logs <container_name_or_id>To continuously view new log entries, use the -f flag:
docker logs -f <container_name_or_id>Docker Stats
The docker stats command displays real-time resource usage of running containers, including CPU, memory, network, and disk I/O usage. It is useful for monitoring container performance.
docker statsTo view statistics for a specific container:
docker stats <container_name_or_id>Docker CP
The docker cp command is used to copy files and directories between a Docker container and the local host system. It is useful when you need to transfer files without rebuilding the container.
docker cp <container_name_or_id>:/path/to/file /host/pathTo copy a file from the host into a container:
docker cp /host/path <container_name_or_id>:/container/pathDocker Volume
Docker volumes are used to store persistent data outside the container's writable layer. This allows data to remain available even when a container is removed.
To list Docker volumes:
docker volume lsTo create a volume:
docker volume create <volume_name>To inspect a volume:
docker volume inspect <volume_name>Docker Kill
The docker kill command immediately stops a running container by sending a kill signal. It can be used when a container does not respond to the normal docker stop command.
docker kill <container_name_or_id>