Docker Commands
Docker provides commands which interact and work in client-server environment. Docker is Linux compliant software.
We have listed some important and useful Docker commands as below:.
Docker version:- This command is used to show the version of installed Docker on your machine.
sudo docker version
Docker Run:- The docker run command creates a container from a given image and starts the container using a given command.
docker run -d ubuntu
-d : It is used to run containers in detached mode.
Docker images:– This command is used to display all the images currently installed on your system.
docker images
Docker ps:- ps stands for ‘process status’ which shows the status of all running processes along with their IDs. docker ps is a majorly used command which is used to view all the running containers along with their container ID.
docker ps -l
-l : it is used to show the latest available container.
Docker ps – a
docker ps -a
The -a option is used to list all containers. As below:
Docker stop: This below command is used to stop the running container:
docker stop container_id
container_id : It is an Id assigned by the Docker to the container.
Docker rmi:- This command is used to remove the docker image
docker rmi image-id
Delete all images:- This command is used to remove all docker images
docker rmi $(docker images -q)
Delete all images forcefully:- This command is used to remove all docker images forcefully.
docker rmi -f $(docker images -q)
-f : It is used to delete images forcefully. This will delete all the images even if it is used by a running container.
Docker rm:- This command is used to delete all the running containers.
docker rm -f $(docker ps -a -q)
Docker exec:- This command is used to enter into Docker container
docker exec -it container-id /bin/bash
Inspect information of a container
sudo docker inspect (container-id)
Build Docker Image from a Dockerfile
docker build -t image-name docker-file-location
-t : it is used to tag Docker images with the provided name.
Mount Volume to a docker container, using below command we can mount (https://salesforcedrillers.com/learn-devops/docker-volume/)
Docker with volume
docker run -it -d -v <path/of/volume>:<path/of/volume/inside/container> (image-name)
-v: It is used to mount volume