How to create docker image from Dockerfile?

To create an image from Dockerfile use following commands:

docker build -t user/app .

How to list docker images?

To view list of all available docker images on your computer run:

docker images

How to remove docker image?

To remove a docker image follow commands below:

# first, list all images
docker images

# find image id from above command
# now remove image using id
docker rmi <id>

How to list current process in docker?

To list running images in docker run following commands:

# list all running images
docker ps

# list all running/exited processes
docker ps -a

# to kill a running process
# grab the id from above command
docker kill <id>

How to create a container from image?

To create a new container without starting it using existing image run:

# syntax: docker create [image]
# create a new ubuntu image
docker create -it ubuntu bash

# to start a container get the id
# from above command when you create an image
# and run following command
docker start -a -i <containerID>

How to use docker hub?

Followings are some of the commands related to docker hub:

# login to docker hub
docker login

# pull a new image from docker hub
docker pull <image>

# push local image to docker hub
docker push <user/image>

# search for image on docker hub
docker search <term>

How to clean up docker container?

To kill docker container run following commands:

# kill specific container
docker kill <containerID>

# kill all running containers
docker kill $(docker ps -q)

# remove a container that is not running
docker rm <containerID>

# delete containers that are not running
docker rm $(docker ps -a -q)

I hope you enjoyed docker cheat sheet. Comment below for new commands.