Docker Cheatsheet

Install Docker

Installing Docker on Debian based distro

sudo apt-get install docker

Installing Docker on Windows

Go to https://hub.docker.com/editions/community/docker-ce-desktop-windows, download and install it.
Once Docker is installed, use Docker Interactive Window or Powershell to use the following commands.

Login to docker

To use Docker's public images, you must have a Docker ID or account,
go to https://hub.docker.com/ and register your account if you don't have one as yet.
Otherwise, run the following command:


docker login

Checking if there’s any container running

docker ps

List all containers, event if they aren’t running

docker ps -a

Running a container

Docker run creates a new container from the docker image and starts the container
docker run tutum/hello-world

Naming a container

docker run --name web1 tutum/hello-world

Running a docker container on a particular port

# docker run --name web2 -p exposePORTt:localPort tutum/hello-world
docker run --name web2 -p 8080:80 tutum/hello-world

Running docker containers in the background using daemon

docker run -d --name web3 -p 8080:80 tutum/hello-world
docker run -d --name web4 -p 8081:80 tutum/hello-world

Get logs for a container

docker logs web3

Get all logs for all containers

for dlog in `docker ps -a -q`; do docker logs $dlog; done

Stopping a docker container

docker stop web3

Stopping more than one docker container

docker stop $(docker ps -a -q)

Starting a docker container

docker start web3

Removing a container

# docker rm <container-name>
docker rm web3
````

### Removing all containers
```bash
docker rm $(docker ps -a -q)

Stop and remove all containers

docker rm $(docker ps -a -q) & docker stop $(docker ps -a -q)

List docker images

docker images

Remove a docker image

docker rmi wordpress

Remove all images

docker rmi $(docker images -q)
Go Back
Menu
×