Docker Command Guide #
Docker is a platform for building, shipping, and running distributed applications in containers. It allows developers to package their applications along with their dependencies into a single unit called a container, which can be run on any machine that has Docker installed.
Here is a list of some of the most commonly used Docker commands along with examples of their usage:
docker build
#
Builds an image from a Dockerfile
Example: docker build -t myimage:latest .
This command builds an image named myimage with the tag latest from the Dockerfile in the current directory (.).
docker run
#
Runs a container from an image
Example: docker run -it myimage:latest
This command runs a container from the myimage image with the tag latest and opens an interactive shell (-it).
docker ps
#
Lists running containers
Example: docker ps
This command lists all running containers.
docker images
#
Lists available images
Example: docker images
This command lists all available images on the local machine.
docker stop
#
Stops a running container
Example: docker stop container_id
This command stops the container with the specified ID (container_id).
docker rm
#
Removes a container
Example: docker rm container_id
This command removes the container with the specified ID (container_id).
docker rmi
#
Removes an image
Example: docker rmi myimage
This command removes the image with the specified name (myimage).
docker pull
#
Pulls an image from a registry
Example: docker pull myimage:latest
This command pulls the myimage image with the tag latest from a registry.
docker push
#
Pushes an image to a registry
Example: docker push myregistry/myimage:latest
This command pushes the myimage image with the tag latest to the myregistry registry.
docker exec
#
Runs a command in a running container
Example: docker exec container_id ls -la
This command runs the ls -la command in the running container with the specified ID (container_id).
docker inspect
#
Displays detailed information about an object
Example: docker inspect container_id
This command displays detailed information about the container with the specified ID (container_id).
docker logs
#
Displays logs from a container
Example: docker logs container_id
This command displays the logs from the container with the specified ID (container_id).
docker network
#
Manages Docker networks
Example: docker network create mynetwork
This command creates a Docker network named mynetwork.
docker volume
#
Manages Docker volumes
Example: docker volume create myvolume
This command creates a Docker volume named myvolume.
Conclusion #
Docker provides a powerful set of commands for building, shipping, and running applications in containers. This guide covers some of the most commonly used commands, but there are many more available. By mastering these commands, you can streamline your Docker workflows and take full advantage of the platform’s capabilities.