Docker Image and Commands
This is similar to the concept of class and object in OOPS.
Docker Image is an executable file that has the instructions on how to build a container.
It provides a blue print just like a class.
Images take less space while containers take more space.
COMMANDS:
visit dockerhub for images.
-> docker pull IMAGE_NAME
This command pulls and downloads the image.
Ex: docker pull hello-world
We can verify if the image exists on docker images by running the command,
-> docker images
To check all the containers available,
-> docker ps -a
There are states of container, they are running and exited. Exited state says that the container is present but it's not currently running.
To build and run containers we use the command,
-> docker run IMAGE_NAME
-> docker run -it IMAGE_NAME
-it refers to interactive mode, where we can access the container from terminal (take input and output).
To check containers that are running,
-> docker ps
After running,
-> docker run -it ubuntu
we will enter into container's terminal and we can verify it by running ls.
The container's terminal will open as root@12333.....c2e:/
in here, we can run all linux commands and the container will be in running state.
to exit from this terminal we can use exit.( it will also stop the state from running).
The docker run (docker run IMAGE_NAME)command will create a new container, but if a container already exists and we want to restart it again, we can use the command
-> docker start CONT_NAME (or) CONT_ID
To stop a container,
-> docker stop CONT_NAME (or) CONT_ID.

Comments
Post a Comment