Docker is an OpenSource containerization platform for Building, Shipping and Running applications using Container Virtualization technology. Docker packages all the dependencies in form of a Docker containers to ensure that our applicaton works seamlessly in any of the environment.
If you are not familiar with Docker and have not installed Docker in your device, you can go through my last article mentioning the installation here.
Docker uses the concept of Docker images to deploy the Docker Containers. Docker Images can be compaed with a template that can be used to create the Docker Containers. Docker Images are read-only templates. Docker Images are available on hub.docker.com and can also be created by users.
- docker search: Used to search for a particular image on DockerHub via command line.
docker search IMAGE_NAME
- docker pull: Used to pull images from DockerHub to Docker Engine for our use.
docker pull IMAGE_NAME
- docker images: Used to list all the available images on our Docker Engine.
- docker run: Creates the container and runs the default or specified command.
docker run IMAGE_NAME docker run IMAGE_NAME COMMAND
The life of a container is the running time of the command or code.
docker run command attaches and runs an image inside of a docker container. The docker run command requires one parameter and that is the image name.
docker run IMAGE_NAME
- To run a specific command in Docker Container,
docker run IMAGE_NAME COMMAND
- To run a container with a specific name,
docker run --name CONTAINER_NAME IMAGE_NAME COMMAND
- To run a container wth an interactive terminal,
docker run -it IMAGE_NAME
- To run a container in background,
docker run -d IMAGE_NAME COMMAND
- To delete a container as soon as it finishes it's execution,
docker run --rm IMAGE_NAME COMMAND
The options with the docker run command can be coupled together and used accordingly.
docker ps: Used to list the docker containers.
- To list all the running docker containers,
- To list all the docker containers, (weather running or stopped),
docker ps -a
- To list only the ID's of docker containers,
docker ps -q
The options with the docker ps command can be coupled together and used accordingly.
- docker stop: Stops a container after closing all the running programs.
docker stop CONTAINER_ID docker stop CONTAINER_NAME
(Can be considered as properly shutting down the device)
- docker kill: Stops a container forcefully.
docker kill CONTAINER_ID docker kill CONTAINER_NAME
(Can be thought of forcefully stopping the device by removing the power cable)
- docker start: Used to start an existing stopped docker container.
docker start CONTAINER_ID docker start CONTAINER_NAME
- docker exec: Used to run a child process along with the parent process.
docker exec CONTAINER COMMAND
- docker rm: Used to remove a container from the memory. (Permanently delete)
docker rm CONTAINER_ID docker rm CONTAINER_NAME
- docker rmi: Used to remove a pulled docker image.
docker rmi IMAGE_NAME