Skip to content

khushmeet/docker-command

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

docker-command

HELPFUL DOCKER COMMANDS

  1. docker ps  list running containers. 
  2. docker ps -a list all container including stopped container
  3. docker pull  download a image from Docker Hub registry. Link to the docker image is always shown on the right at dockerhub.
  4. docker build  is used to build your own container based on a Dockerfile. Common use is docker build . to build a container based on the Dockerfile in the current directory (the dot). docker build -t "myimage:latest" . creates a container and stores the image under the given name
  5. docker images or docker image ls shows all local storage images
  6. docker run  Run a docker container based on an image, i. e. docker run myimage -it bash. If no local image can be found docker run automatically tries to download the image from Docker hub.
  7. docker logs display the logs of a container, you specified. To continue showing log updates just use docker logs -f mycontainer
  8. docker volume ls  lists the volumes, which are commonly used for persisting data of Docker containers.
  9. docker network ls - list all networks available for docker container
  10. docker network connect adds the container to the given container network. That enables container communication by simple container name instead of IP.
  11. docker rm   removes one or more containers. docker rm mycontainer, but make sure the container is not running
  12. docker rmi  removes one or more images. docker rmi myimage, but make sure no running container is based on that image
  13. docker stop   stops one or more containers. docker stop mycontainer stops one container, while docker stop $(docker ps -a -q) stops all running containers. 
  14. docker start - starts a stopped container using the last state
  15. docker update --restart=no updates container policies, that is especially helpful when your container is stuck in a crash loop
  16. docker cp to copy files from a running container to the host or the way around. docker cp :/etc/file . to copy /etc/file to your current directory.

SOME OTHER COMBINATION THAT HELP A LOT

  • kill all running containers with docker kill $(docker ps -q)
  • delete all stopped containers with docker rm $(docker ps -a -q)
  • delete all images with docker rmi $(docker images -q)
  • update and stop a container that is in a crash-loop with docker update --restart=no && docker stop
  • bash shell into container docker exec -i -t /bin/bash - if bash is not available use /bin/sh
  • bash shell with root if container is running in a different user context docker exec -i -t -u root /bin/bash

SOME iMPORTANT lINKS

https://gist.github.com/giansalex/2776a4206666d940d014792ab4700d80

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published