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 -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 -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
This command lists all running containers.
This command lists all available images on the system.
docker pull ubuntu:latest
This command pulls the latest version of the Ubuntu image from Docker Hub.
docker push my-registry/my-image:latest
This command pushes the my-image:latest image to the my-registry registry.
docker stop my-container
This command stops the my-container container.
docker rm my-container
This command removes the my-container container.
docker rmi my-image:latest
This command removes the my-image:latest image.
docker exec -it my-container bash
This command runs the
bash command in the my-container container in interactive mode.
docker inspect my-container
This command displays detailed information on the my-container container.
This command runs the Docker Compose file in the current directory.
docker network ls
This command lists all Docker networks on the system.
docker volume create my-volume
This command creates a Docker volume with the name my-volume.
docker logs my-container
This command displays the logs for the my-container container.
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 my-image:latest my-registry/my-image:latest
This command adds the my-registry registry to the my-image:latest image tag.
docker system info
This command shows information about the Docker system..