A Docker Image is a collection of all the required files for an executable. Docker Images are layered, i.e. are stacked on top of each other, with the base image having no parent images.

Docker images can be downloaded from registires, Docker Hub being an example, built from Dockerfiles or from existing containers.

Building an Image from a Dockerfile

Given a Dockerfile:

FROM ubuntu
CMD echo HelloWorld

an image can be built by:

docker build -t ubuntu-helloworld .

Downlading an Image From a Registry

docker pull ubuntu

Creating an Image from a Container

A container can be commited using the commit command in a desired state to be stored as an image.

docker run -it --rm ubuntu

# Run the following inside the container
apt-get update
apt-get install -y wget

# Stop the container by exiting

docker commit container-id koraytugay/ubuntu_wget
# At this point you should have a new image you can start anytime you like
# that comes with wget

docker run -it --rm koraytugay/ubuntu
# Pulling an image
docker pull repository-name:tag
# Examples
docker image pull mongo:3.3.11
docker pull hello-world # equivalent to :latest

# Listing images
docker image ls

# Removing an image
docker image rm image-id