docker.cheat 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. % docker
  2. # Remove an image
  3. docker image rm <image_id>
  4. # Delete an image from the local image store
  5. docker rmi <image_id>
  6. # Clean none/dangling images
  7. docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
  8. # Force clean none/dangling images
  9. docker rmi $(docker images --filter "dangling=true" -q --no-trunc) -f
  10. # List all images that are locally stored with the Docker engine
  11. docker images
  12. # Build an image from the Dockerfile in the current directory and tag the image
  13. docker build -t <image>:<version> .
  14. # Pull an image from a registry
  15. docker pull <image>:<version>
  16. # Stop a running container through SIGTERM
  17. docker stop <container_id>
  18. # Stop a running container through SIGKILL
  19. docker kill <container_id>
  20. # List the networks
  21. docker network ls
  22. # List the running containers
  23. docker ps
  24. # Delete all running and stopped containers
  25. docker rm -f $(docker ps -aq)
  26. # Create a new bash process inside the container and connect it to the terminal
  27. docker exec -it <container_id> bash
  28. # Print the last lines of a container's logs
  29. docker logs --tail 100 <container_id> | less
  30. # Print the last lines of a container's logs and following its logs
  31. docker logs --tail 100 <container_id> -f
  32. # Create new network
  33. docker network create <network_name>
  34. $ image_id: docker images --- --headers 1 --column 3
  35. $ container_id: docker ps --- --headers 1 --column 1
  36. % docker-compose
  37. # Builds, (re)creates, starts, and attaches to containers for all services
  38. docker-compose up
  39. # Builds, (re)creates, starts, and dettaches to containers for all services
  40. docker-compose up -d
  41. # Builds, (re)creates, starts, and attaches to containers for a service
  42. docker-compose up -d <service_name>
  43. # Builds, (re)creates, starts, and dettaches to containers for a service
  44. docker-compose up -d <service_name>
  45. # Print the last lines of a service’s logs
  46. docker-compose logs --tail 100 <service_name> | less
  47. # Print the last lines of a service's logs and following its logs
  48. docker-compose logs -f --tail 100 <service_name>
  49. # Stops containers and removes containers, networks created by up
  50. docker-compose down