Skip to content

Instantly share code, notes, and snippets.

@panna-ahmed
Last active January 13, 2022 22:32
Show Gist options
  • Save panna-ahmed/62d69484ed17c8cd1daa5448f15f109c to your computer and use it in GitHub Desktop.
Save panna-ahmed/62d69484ed17c8cd1daa5448f15f109c to your computer and use it in GitHub Desktop.
My docker commands
docker image ls //get all the images installed in this pc
minikube docker-env //get environment settings to make docker command talk to minikube
eval $(minikube -p minikube docker-env) //setting talking docker daemon
minikube ip
docker ps  //list running containers.
docker ps -a //list all container including stopped container
docker pull  //download a image from Docker Hub registry
docker build //is used to build your own container based on a Dockerfile
docker build -t "myimage:latest" //creates a container and stores the image under the given name
docker images or docker image ls //shows all local storage images
docker run  //Run a docker container based on an image. If no local image can be found docker run automatically tries to download the image from Docker hub.
docker logs //display the logs of a container, you specified. To continue showing log updates just use docker logs -f mycontainer
docker volume ls  //lists the volumes
docker network ls //list all networks available for docker container
docker rm   //removes one or more containers. docker rm mycontainer, but make sure the container is not running
docker rmi //removes one or more images. docker rmi myimage, but make sure no running container is based on that image
docker stop //stops one or more containers. docker stop mycontainer stops one container, while docker stop $(docker ps -a -q) stops all running containers.
docker start //starts a stopped container using the last state
docker update –restart=no //updates container policies, that is especially helpful when your container is stuck in a crash loop
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 combinations 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment