Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. + `docker ps`  
  2. —  Lists running containers. Some useful flags include: -a / -all for all containers (default shows just running) and —-quiet /-q to list just their ids (useful for when you want to get all the containers).
  3. + `docker pull`  
  4. —  Most of your images will be created on top of a base image from the Docker Hub registry. Docker Hub contains many pre-built images that you can pull and try without needing to define and configure your own. To download a particular image, or set of images (i.e., a repository), use docker pull.
  5. + `docker build`  
  6. —  The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL. Use the -t flag to label the image, for example docker build -t my_container . with the . at the end signalling to build using the currently directory.
  7. + `docker run`  
  8. —  Run a docker container based on an image, you can follow this on with other commands, such as -it bash to then run bash from within the container. Also see Top 10 options for docker run — a quick reference guide for the CLI command. docker run my_image -it bash
  9. + `docker logs`  
  10. —  Use this command to display the logs of a container, you must specify a container and can use flags, such as --follow to follow the output in the logs of using the program. docker logs --follow my_container
  11. + `docker volume ls`
  12.  — This lists the volumes, which are the preferred mechanism for persisting data generated by and used by Docker containers.
  13. + `docker rm`  
  14. —  Removes one or more containers. docker rm my_container
  15. + `docker rmi`  
  16. —  Removes one or more images. docker rmi my_image
  17. + `docker stop`  
  18. —  Stops one or more containers. docker stop my_container stops one container, while docker stop $(docker ps -a -q) stops all running containers. A more direct way is to use docker kill my_container, which does not attempt to shut down the process gracefully first.
  19.  
  20. Use them together, for example to clean up all your docker images and containers:
  21.  
  22. + kill all running containers with `docker kill $(docker ps -q)`
  23. + delete all stopped containers with `docker rm $(docker ps -a -q)`
  24. + delete all images with `docker rmi $(docker images -q)`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement