Hi learners 😃
IN THIS BLOG YOU WILL LEARN ABOUT A FEW DOCKER COMMANDS
Before that, if you haven't watched the previous blog on introduction to docker, please read it and come back so that you will get a clear understanding.
LETS DIVE IN
Before that, open docs.docker.com
FEW DOCKER COMMANDS
This command will display the version of the docker you installed.
$ docker --version
This command displays the list of commands available in docker and their uses.
$ docker --help
This command pulls an image from the docker hub.
Here the image is comparable to a snapshot in a virtual machine (VM) environment. If you run virtual machines on your machine you will be using a .iso file, which is an example of an image.
You can pull any image from the hub or, in simple words, you are just downloading the image from the hub. For example, you can pull an Ubuntu image.
$ docker pull [OPTIONS] NAME[:TAG|@DIGEST]
This command creates a container for the given image and starts the container for that image.
$ docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
There are lots of options you can give with the docker run command. For example, you can allocate CPU core counts, custom DNS, and more. You can give whatever you can give to your PC or laptop.
In this example, use '-it'.
The -it instructs Docker to allocate a pseudo-TTY connected to the container’s stdin, creating an interactive bash shell in the container.
$ docker run -it ubuntu bash
In the above screenshot, you can see that a new terminal will be spawned and an id for the container will be created. In the screenshot, you will notice that the root@some_code, that is not the container id.
This container will list the running container by default.
$ docker ps
This command will stop the running container.
$ docker stop [OPTIONS] CONTAINER [CONTAINER...]
This container will remove one or more containers.
$ docker rm [OPTIONS] CONTAINER [CONTAINER...]
This command lists the top-level images, their repositories, tag and their size.
$ docker images [OPTIONS] [REPOSITORY[:TAG]]
This command will kill one or more containers. The main process inside the container is the SIGKILL signal (default), or the signal that is specified by the --signal option.
$ docker kill [OPTIONS] CONTAINER [CONTAINER...]
This command runs a new command in a running container.
$ docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
- First start a container.
$ docker run --name ubuntu-file -it ubuntu bash
- Next, execute a command in the container.
$ docker exec -d ubuntu-file touch /root/file.txt
This will create file.txt in the root.
I will share a cheatsheet for docker commands.
DON'T STOP HERE. HAVE THE CHEATSHEET AND REFER TO THE DOCKER'S OFFICIAL DOCUMENTATION TO LEARN MORE.
docker compose, build
**AND WE HAVE COME TO THE END OF THIS BLOG. WAIT, YOU'VE NOTICED THAT I MISSED SOME COMMANDS. YES, IN THE NEXT BLOG WE WILL BE COVERING THOSE COMMANDS SINCE FOR THOSE WE NEED TO KNOW ABOUT A FEW TOPICS LIKE YAML, CREATING DOCKER FILES.
Until then bye from Sabarish❤️.