These are just some of the most commonly used Docker commands. There are many more commands available that can be used to manage and interact with Docker containers and images. You can find a full list of commands in the Docker documentation.
docker build
docker build -t my-image:latest .
This command builds an image from the Dockerfile located in the current directory, with the tag my-image:latest . The “-t” option specifies the name and tag of the image, while the full stop at the end of the command specifies the build context, which is the current directory containing the Dockerfile.
docker run
docker run -it my-image:latest
This command runs a container from the my-image:latest image in “-it” interactive mode.
To set a restart policy for your container, you can use the “–restart” flag with the “always” option:
docker run --restart=always my-image:latest
If you want to update the restart policy of an existing container, you can use the “docker update” command:
docker update --restart=always my-container
docker ps
docker ps
This command lists all running containers.
docker images
docker images
This command lists all available images on the system.
docker pull
docker pull ubuntu:latest
This command pulls the latest version of the Ubuntu image from Docker Hub.
docker push
docker push my-registry/my-image:latest
This command pushes the my-image:latest image to the my-registry registry.
docker stop
docker stop my-container
This command stops the my-container container.
docker rm
docker rm my-container
This command removes the my-container container.
docker rmi
docker rmi my-image:latest
This command removes the my-image:latest image.
docker exec
docker exec -it my-container bash
This command runs the bash
command in the my-container container in interactive mode.
docker inspect
docker inspect my-container
This command displays detailed information on the my-container container.
docker-compose
docker-compose up
This command runs the Docker Compose file in the current directory.
docker network
docker network ls
This command lists all Docker networks on the system.
docker volume
docker volume create my-volume
This command creates a Docker volume with the name my-volume.
docker logs
docker logs my-container
This command displays the logs for the my-container container.
docker commit
docker commit my-container my-new-image
This command creates a new image named my-new-image from the changes made to the my-container container.
docker tag
docker tag my-image:latest my-registry/my-image:latest
This command adds the my-registry registry to the my-image:latest image tag.
docker system
docker system info
This command shows information about the Docker system..