Reading Time: 2 minutes
Below are some of the most useful and commonly used Docker commands along with usage examples:
docker run
Thedocker run
command is used to start a Docker container from an image. For example, if you want to start an Ubuntu container:
docker run ubuntu
docker ps
Thedocker ps
command shows a list of all running containers. To display all containers (including those not running), you can use the-a
option.
docker ps
docker stop
Thedocker stop
command is used to stop a running container. For example, if you want to stop a container with ID 123456789:
docker stop 123456789
docker rm
Thedocker rm
command is used to remove a container. For example, if you want to remove a container with ID 123456789:
docker rm 123456789
docker images
Thedocker images
command shows a list of all downloaded Docker images on the system.
docker images
docker pull
Thedocker pull
command is used to download a Docker image from a repository.
docker pull ubuntu
docker push
Thedocker push
command is used to upload a Docker image to a repository.
docker push myrepository/myimage
docker build
Thedocker build
command is used to build a Docker image from a Dockerfile.
docker build -t myimage .
docker-compose
Thedocker-compose
command is used to manage multiple Docker containers through a YAML file.
docker-compose up docker-compose down
docker exec
Thedocker exec
command is used to execute a command in a running container.
docker exec -it mycontainer bash
These are just some of the most commonly used and useful Docker commands. There are many more commands and options available in Docker, and more details can be found in the official Docker documentation.