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
Docker version 28.0.4, build b8034c0
docker run ubuntu
docker ps -a
docker run -it ubuntu bash
cat /etc/*release*
exit
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;
docker run -d ubuntu sleep 2000
docker stop nostalgic_mcnulty
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
docker rm a8b90fbbb6f5
docker images
docker rmi ubuntu
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
docker exec 6fe093e500ff cat /etc/*release*
Comments
Post a Comment