Docker Commands Cheatsheet


Docker Commands Cheat Sheet
Container Lifecycle
Creating and Starting a Container
docker run -d --name my_container nginx- Use this command to create and start a container namedmy_containerusing thenginximage.
Starting, Stopping, and Restarting Containers
docker stop my_container- Stops the specified container.docker start my_container- Starts a previously stopped container.docker restart my_container- Restarts a container.
Listing Containers
docker ps- Lists all currently running containers.docker ps -a- Lists all containers, including those that are stopped.
Image Management
Fetching an Image from a Registry
docker pull ubuntu- Retrieves theubuntuimage from the Docker Hub or other specified registry.
Building an Image from a Dockerfile
docker build -t my_image .- Builds an image namedmy_imagefrom a Dockerfile in the current directory.
Listing and Removing Images
docker images- Lists all local Docker images.docker rmi my_image- Removes the specified image from the local system.
Container Operations
Interacting with Containers
docker exec -it my_container bash- Executes a command (bashin this case) inside a running container.docker attach my_container- Attaches to a running container for interaction.docker logs my_container- Displays logs from the specified container.
Managing Container Resources
docker cp file.txt my_container:/path/to/destination- Copies files between a container and the host system.docker pause my_containeranddocker unpause my_container- Pauses or unpauses a running container.docker inspect my_container- Displays detailed information about a specific container.
Networking
Network Management
docker network ls- Lists all networks available on the Docker host.docker network create my_network- Creates a new network.docker network connect my_network my_containeranddocker network disconnect my_network my_container- Connects or disconnects a container from a network.
Volume Management
Volume Commands
docker volume ls- Lists all Docker volumes.docker volume create my_volume- Creates a new volume namedmy_volume.docker volume rm my_volume- Removes the specified volume.docker volume inspect my_volume- Provides detailed information about a specific volume.
Follow Rohit Ghumare for more such an amazing content.
Check DevOpscommunity.in for more FREE resources.
About the author
Devrel manager cerbos.dev
Comments
Join the discussionNo comments yet. Be the first to comment.


