60 Frequently Used Docker Commands Cheat Sheet

Table Of Contents
  1. 1. List Docker images:
  2. 2. List running containers:
  3. 3. List all containers (including stopped):
  4. 4. Pull an image from Docker Hub:
  5. 5. Run a container from an image:
  6. 6. Run a container in detached mode (background):
  7. 7. Run a container with a custom name:
  8. 8. Stop a running container:
  9. 9. Start a stopped container:
  10. 10. Remove a container:
  11. 11. Remove an image:
  12. 12. Execute a command in a running container:
  13. 13. Show logs of a container:
  14. 14. Build an image from Dockerfile:
  15. 15. Inspect a container (details):
  16. 16. Inspect an image (details):
  17. 17. List networks:
  18. 18. Create a new network:
  19. 19. Attach a network to a container:
  20. 20. Remove a network:
  21. 21. Pause a running container:
  22. 22. Unpause a paused container:
  23. 23. Restart a container:
  24. 24. Display Docker disk usage:
  25. 25. Remove all stopped containers:
  26. 26. Remove all unused images:
  27. 27. Remove all unused networks:
  28. 28. Remove all unused volumes:
  29. 29. Display Docker version information:
  30. 30. Display Docker system-wide information:
  31. 31. Disconnect a container from a network:
  32. 32. Display Docker usage information including storage and memory:
  33. 33. Display Docker storage usage by volume:
  34. 34. Display detailed information about Docker events in real-time:
  35. 35. Display detailed information about Docker swarm nodes:
  36. 36. Display detailed information about Docker services:
  37. 37. Create a new Docker service:
  38. 38. Scale a Docker service to a specific number of replicas:
  39. 39. Update a Docker service with a new image or configuration:
  40. 40. Remove a Docker service:
  41. 41. Display information about a specific Docker swarm:
  42. 42. Join a Docker swarm as a worker or manager:
  43. 43. Leave a Docker swarm:
  44. 44. Promote a node to be a manager in Docker swarm:
  45. 45. Demote a manager node to be a worker in Docker swarm:
  46. 46. Drain a node in Docker swarm to prevent new tasks from being scheduled:
  47. 47. Update the configuration of a Docker swarm:
  48. 48. Display detailed information about Docker configs:
  49. 49. Create a Docker config:
  50. 50. Remove a Docker config:
  51. 51. Display detailed information about Docker secrets:
  52. 52. Create a Docker secret:
  53. 53. Remove a Docker secret:
  54. 54. Display detailed information about Docker plugins:
  55. 55. Install a Docker plugin:
  56. 56. Upgrade a Docker plugin:
  57. 57. Remove a Docker plugin:
  58. 58. Enable experimental features in Docker:
  59. 59. Display information about Docker network plugins:
  60. 60. Configure Docker to use a specific network plugin:
  61. Conclusion

1. List Docker images:

docker images

2. List running containers:

docker ps

3. List all containers (including stopped):

docker ps -a

4. Pull an image from Docker Hub:

docker pull <image_name>

5. Run a container from an image:

docker run <image_name>

6. Run a container in detached mode (background):

docker run -d <image_name>

7. Run a container with a custom name:

docker run --name <container_name> <image_name>

8. Stop a running container:

docker stop <container_id/name>

9. Start a stopped container:

docker start <container_id/name>

10. Remove a container:

docker rm <container_id/name>

11. Remove an image:

docker rmi <image_id/name>

12. Execute a command in a running container:

docker exec <container_id/name> <command>

13. Show logs of a container:

docker logs <container_id/name>

14. Build an image from Dockerfile:

docker build -t <image_name> <path_to_Dockerfile>

15. Inspect a container (details):

docker inspect <container_id/name>

16. Inspect an image (details):

docker inspect <image_id/name>

17. List networks:

docker network ls

18. Create a new network:

docker network create <network_name>

19. Attach a network to a container:

docker network connect <network_name> <container_id/name>

20. Remove a network:

docker network rm <network_name>

21. Pause a running container:

docker pause <container_id/name>

22. Unpause a paused container:

docker unpause <container_id/name>

23. Restart a container:

docker restart <container_id/name>

24. Display Docker disk usage:

docker system df

25. Remove all stopped containers:

docker container prune

26. Remove all unused images:

docker image prune

27. Remove all unused networks:

docker network prune

28. Remove all unused volumes:

docker volume prune

29. Display Docker version information:

docker version

30. Display Docker system-wide information:

docker info

31. Disconnect a container from a network:

docker network disconnect <network_name> <container_id/name>

32. Display Docker usage information including storage and memory:

docker system info

33. Display Docker storage usage by volume:

docker volume df

34. Display detailed information about Docker events in real-time:

docker events

35. Display detailed information about Docker swarm nodes:

docker node ls

36. Display detailed information about Docker services:

docker service ls

37. Create a new Docker service:

docker service create --name <service_name> <image_name>

38. Scale a Docker service to a specific number of replicas:

docker service scale <service_name>=<replica_count>

39. Update a Docker service with a new image or configuration:

docker service update --image <new_image> <service_name>

40. Remove a Docker service:

docker service rm <service_name>

41. Display information about a specific Docker swarm:

docker swarm inspect

42. Join a Docker swarm as a worker or manager:

docker swarm join --token <token> <manager_ip>

43. Leave a Docker swarm:

docker swarm leave

44. Promote a node to be a manager in Docker swarm:

docker node promote <node_id>

45. Demote a manager node to be a worker in Docker swarm:

docker node demote <node_id>

46. Drain a node in Docker swarm to prevent new tasks from being scheduled:

docker node update --availability drain <node_id>

47. Update the configuration of a Docker swarm:

docker swarm update

48. Display detailed information about Docker configs:

docker config ls

49. Create a Docker config:

docker config create <config_name> <file_name>

50. Remove a Docker config:

docker config rm <config_name>

51. Display detailed information about Docker secrets:

docker secret ls

52. Create a Docker secret:

docker secret create <secret_name> <file_name>

53. Remove a Docker secret:

docker secret rm <secret_name>

54. Display detailed information about Docker plugins:

docker plugin ls

55. Install a Docker plugin:

docker plugin install <plugin_name>

56. Upgrade a Docker plugin:

docker plugin upgrade <plugin_name>

57. Remove a Docker plugin:

docker plugin rm <plugin_name>

58. Enable experimental features in Docker:

docker daemon --experimental

59. Display information about Docker network plugins:

docker network plugin ls

60. Configure Docker to use a specific network plugin:

docker network create --driver <plugin_name> <network_name>

Conclusion

In this article, we learned 60 frequently used docker commands. You can bookmark this page to refer to anytime in the future.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top