Docker commands cheat sheet.
Hello everyone Shikhar this side. Before jumping to commands, you should know Basic questions like what Docker is. , What is a Container? and What is software containerization?
What is Docker ?
Docker is an open-source platform that enables developers to automate the development, scaling, and management of application using Containerization.
Now Your next question will be What is a Container?
A container is a loosely isolated environment that allows us to build and run software packages. These software packages include code and all dependencies to run application quickly and reliably on any computing environment. We call these packages as container images.
What is software containerization?
Software containerization is an OS virtualization method that is used to deploy and run containers without using a VM. Containers can run on physical hardware, in the cloud, VMs, and across multiple OSs.
Now we will be going through some important commands.
To get the docker version.
1. docker version
2. docker images
- List all the docker images present in the docker server.
3. docker image inspect [image-id]
- Display detailed image information for a given image ID.
4. docker image rm [image-id]
- Remove one or more images for a given image ids.
5. docker build . -t [image-name]
- Generate a docker image based on a Dockerfile
6. docker run -p [hostpost]: [containerport] [image_name]
- Start docker based on a given image on a specific port.
7. docker ps
- Show all running containers.
8. docker ps -a
- Show all containers including running and stopped.
9. docker container start [container-id]
- Start one or more stopped containers.
10. docker container pause [container-id]
- Pause all processes within one or more containers.
11. docker container unpause [container-id]
- Resume all processes within one or more containers.
12. docker container stop [container-id]
- Stop one or more running containers.
13. docker container kill [container-id]
- Kill one or more running containers instantly.
14. docker container restart [container-id]
- Restart one or more containers.
15. docker container inspect [container-id]
- Inspect all details for a given container ID.
16. docker container logs [container-id]
- Fetch the logs of a given container-id.
17. docker container logs -f [container-id]
- Follow the log output of a given container-id
18. docker rm [container-id]
- Remove one or more containers based on container-id.
19. docker container prune
- Remove all stopped containers.
20. docker image push [container-repository/username: tag]
- Push an image from a container registry
21. docker image pull [container-repository/username: tag]
- Pull an image from a container registry
22. docker image prune
- Remove all unused images
23. docker container stats
- Show all container statics like CPU, Memory, I/O usage
24. docker system prune
- Remove stopped containers, dangling images, and unused networks, volumes, and cache.
25. docker rmi [image-id]
- Remove one or more images based on the image id.
26. docker login -u [username]
- Login to the docker hub container registry.
27. docker logout
- Log out from the docker hub container registry.
28. docker history [image- name]
- Display the intermediate layers and commands that were executed when building the image.
29. docker exec -it [container-id] sh
- Open a shell inside a running container and execute commands.
30. docker compose up
- To create and start containers based on a given docker-compose file.
31. docker compose down
- Stop and remove the containers for services defined in the compose file.
These are some of the important commands related to docker.
Thanks for reading….