1. Check Docker version installed.
docker --version
2. Display system-wide information.
docker info
3. List all commands or get help on a specific one.
docker help
4. Download an image from Docker Hub.
docker pull <image>
5. List all local images.
docker images
6. Build image from a Dockerfile in current directory.
docker build -t <name> .
7. Rename an image locally.
docker tag <image> <new-name>
8. Remove an image.
docker rmi <image>
9. Save an image to a .tar archive.
docker save -o <file>.tar <image>
10. Load image from a .tar archive.
docker load -i <file>.tar
11. Show layers of an image.
docker history <image>
12. Run a container.
docker run <image>
13. Run interactively with terminal access.
docker run -it <image> /bin/bash
14. Run in detached (background) mode.
docker run -d <image>
15. Map ports (host:container).
docker run -p 8080:80 <image>
16. Give a name to the container.
docker run --name <name> <image>
17. Start an existing container.
docker start <container>
18. Stop a running container.
docker stop <container>
19. Restart a container.
docker restart <container>
20. Remove a container.
docker rm <container>
21. List running containers.
docker ps
22. List all containers (including stopped).
docker ps -a
23. View logs of a container.
docker logs <container>
24. Run commands inside a running container.
docker exec -it <container> /bin/bash
25. Attach to a running container.
docker attach <container>
26. Get detailed container info.
docker inspect <container>
27. Show real-time usage (CPU, memory, etc...).
docker stats
28. List volumes.
docker volume ls
29. Create a volume.
docker volume create <name>
30. Mount volume into container.
docker run -v <host_dir>:<container_dir> <image>
** 31. Delete a volume.**
docker volume rm <name>
32. Copy files from container to host.
docker cp <container>:<path> <host>
33. Copy files to container.
docker cp <host> <container>:<path>
34. Set base image.
FROM <base_image>
35. Execute command during build.
RUN <command>
36. Copy files into image.
COPY <src> <dest>
37. Like COPY, but with more features (e.g., URL support).
ADD <src> <dest>
38. Set working directory.
WORKDIR /app
39. Default command when container runs.
CMD ["command", "arg"]
40. Document the port the container listens on.
EXPOSE <port>
41. Set environment variables.
ENV <key>=<value>
42.List all networks.
docker network ls
43. Create a custom network.
docker network create <name>
44. View network details.
docker network inspect <name>
45. Connect container to network.
docker network connect <net> <container>
46. Disconnect from a network.
docker network disconnect <net> <container>
47. Start services defined in docker-compose.yml.
docker-compose up
48. Stop and remove containers/networks/volumes.
docker-compose down
49. Build services.
docker-compose build
50. List running containers.
docker-compose ps
51. Tail logs for services.
docker-compose logs -f
Top comments (0)