The most basic docker commands for beginners in 2025

I used to paly with docker since 2020, but I heard about docker before covid 19. I was curious about new technology and I felt same for docker too. But I was afraid off, cause it seems some difficult with it’s complex commands. Even when I used to play with personal projects I found it difficult to understand but I just copied and paste the command and finish whatever I needed.



Now I thought it’s the time to truly understand the commands what I am actually doing with those commands. Today I am going to write and share the few commands which I think is must needed for beginners not only for finishing the personal small projects but also have clear understandings of those commands and so that I can re-check those if I need later on.

I guess you know how to install docker locally - I am not going to describe here, but I will share in details later.

First we will check the version of your installed docker or do you have a installed docker instances on to your computer! By typing below command.

docker --version

Mine is:

Docker version 28.0.4, build b8034c0
Now I will try to run a docker image by typing any image name hosted on hub.docker.com/explore and get the any image name you wish. I use ubuntu, when we run the command it will first try to check if the image is available locally and if not it will pull the image from docker repositories. And after making a local copy the image will run locally and exit if no tasks has been assigned.

docker run ubuntu
        


Let's have a look into our next command docker ps -a

docker ps -a
This will show you the total container you had run and also existing running container too. In our case we have tried to run the ubuntu image and this image already ran and exited with a code as we didn't provide any instructions to process.



Now let us try to run a container with some tasks to process and try to check back again.

docker run -it ubuntu bash
With the above command we are actually inside the container itself and now we can process any tasks we wish. By the cat command we can check the ubuntu release details.

cat /etc/*release*

Now type 
exit


To exit from the container, again we our container is no more running. You can check with.

docker ps 

For running container and what you can see! Noting, because no container is running. Let's run a container for few seconds or minutes by the below command. And one thing I want to mention here that now we will not be inside the container rather we will detach the container individually with -d parameter. 

docker run -d ubuntu sleep 500


docker ps  

If you notice you can see the command "sleep 500" which is the tasks for this container. After tasks finish it will exit from the running mode. Don't over think about it, this is just for understandings we can run the container for any kinds of tasks like: to host wordpress website, vpn server etc;

Now let's stop any running container - how we can do that? Before that we need to run the container for longer periods by  

docker run -d ubuntu sleep 2000
And for sure if it's running try with docker ps and after that try to stop a container by it's name or by it's ID.
docker stop nostalgic_mcnulty



OR
docker stop 26c6a04b9b8b


Now we are going to remove the container, we can remove a container by it's name or ID. To remove with ID you don't need to type the whole name, you can use first few character's of the ID's.

docker rm 26c
OR

docker rm a8b90fbbb6f5


Now I am going to remove the image I had downloaded and now those are not required. One thing to mention is that, the image we ran all stored into locally which occupied storage. Before removing the image, I will first try to see the list of images I have.

docker images

My case I have only tow, let's remove one of them by the image name of ID.

docker rmi ubuntu

OR

docker rmi a04dc4851cbc


Another popular command is pull, this will only pull the image to the local storage and will not run whereas with docker run command it will first check the image locally if the image not available lit will immediately pull from the repositories and make local copy and will run immediately. On the other hand docker pull command only download and make a local copy for later use. This will save time if the image size is bigger.

docker pull ubuntu


And the last not the least command we will learn today is exec, which will be helpful for us if we wants to run or execute any commands or process to a running container from outside. Let's run the container first for 1000 minutes which we pulled few moments back.

docker run -d ubuntu sleep 1000


Now run or execute exec command to see the ubuntu release file following the docker container ID or name.

docker exec 6fe093e500ff cat /etc/*release*


If you see the results like above than you are awesome, you just one step ahead of knowledge about docker commands. All these basic commands are okay for a beginner to work around and play with docker images, docker container etc;




   















Comments