Docker Cheatsheet

Docker Cheatsheet

Who doesn’t like docker, here are some really usefull commands.

Installation

Steps to install Docker.

Ubuntu

  • Remove existing docker installation:sudo apt-get purge docker docker-engine docker.io
  • Update System:sudo apt-get update
  • Install other stuff:sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
  • Add GPG & Update:curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -&sudo apt-get update
  • Add repository:
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
  • Install:sudo apt-get install docker-ce
  • Run without sudo:sudo usermod -aG docker $('whoami')and restart
  • Change default Installation folder
sudo systemctl stop docker
sudo rm -rf /var/lib/docker
sudo ln -s /media/ravindra/Files/Docker/ /var/lib/docker

List images

docker images
docker image ls

List containers

docker container ls

Stop all running containers

docker stop $(docker ps -a -q)

Docker information

docker info

List running containers

docker container ls

List all containers

docker container ls -all

List all containers in quite mode

docker container ls -aq

Getting help

docker container --help
docker image --help

Delete all containers

docker -rm $(docker ps -a -q)
docker -rm $(docker ps -aq)
docker -rm `docker ps -aq`

Delete all images

docker -rmi $(docker images -q)
docker -rmi $(docker image ls -q)

Start a stopped container

docker start <container_name>

Start a stopped container in interactive mode

docker start -i <container_name>

Stop a running container

docker stop <container_name>

Run command in a running container

docker exec <container_name> <command>

Note: You can use command without surrounding it with quotes

Attach console to a running container

docker exec -it <container-id> bash

Original: Updated: