You are on page 1of 14

Images vs Containers

Docker

Images Containers

Templates/ Blueprints for


The running “unit of software”
containers

Contains code + required tools/ Multiple containers can be


runtimes created based on one image

Layer-based, read-only, no Top layer, read & write access,


application data is stored data is lost on shutdown
One Image, Multiple Containers

Container Container Container

Running NodeJS Running NodeJS Running NodeJS


App App App

Image

NodeJS App Code

NodeJS Environment
Finding / Creating Images

We need an Image!

Use an existing, pre-built Create your own, custom


Image Image

Write your own Dockerfile


e.g. via Docker Hub
(based on another Image)
Images & Image Layers

Custom Image

Important: Every
App Code, Config, Setup Steps & Run
command is a layer on
Command
its own!

Third-party or Layers are shared


other custom Node between images
Image
(this keeps Docker
images and containers
Third-party or small)
other custom Debian OS
Image
A Container Is Based On An Image

When you re-build an image, only the


layers that changed will be re-built

Container Layer (read-write)

Container Instruction #3: Image Layer 3


Read-write Image
Instruction #2: Image Layer 2
Read-only

Instruction #1: Image Layer 1


Multiple Containers Can Be Based On The Same Image

3 different containers, separated data

Container Layer 1 Container Layer 2 Container Layer 3

Image Layer 3

Image Layer 2

Image Layer 1
Where To Get Images

Docker Hub or Build your Own

Cloud registry for third-party Configure all tools and setup


images steps you need in your containers

You can pull them to run as Possibly share with other


container developers

You can build your own images Combine third-party images with
based on other images custom setup steps and tools

Typically, you’ll combine both


Images & Containers – First Summary

Container
Image

<Our Code>

<Our Code>
Environment

Environment

Container

<Our Code>

Environment
<Our Code>
Managing Images & Containers

Add --help to see all options


Images Containers

Can be tagged (named) Can be named


-t, docker tag … --name

Can be listed Can be configured in detail


docker images see --help

Can be analyzed Can be listed


docker image inspect docker ps

Can be removed Can be removed


docker rmi, docker prune docker rm
Understanding Image Tags

name : tag

Defines a group of, Defines a specialized


possible more image within a group of
specialized, images images

Example: “node” Example: “14”

Combined: A unique identifier


Sharing Images & Containers

Everyone who has an image, can create


containers based on the image!

Share a Dockerfile Share a Built Image

Download an image, run a


Simply run docker build .
container based on it

Important: The Dockerfile


instructions might need No build step required, everything
surrounding files / folders (e.g. is included in the image already!
source code)
Sharing via Docker Hub or Private Registry

Free Usage Possible!

Docker Hub Private Registry

Any provider / registry you want to


Official Docker Image Registry
use

Public, private and “official”


Only your own (or team) Images
Images

Needs to be
Share: docker push IMAGE_NAME
HOST:NAME to
talk to private
Use: docker pull IMAGE_NAME registry
Key Commands

docker create Create a new container

docker run Create and start a new container based on an image

docker stop Stop a running container


docker start Start a stopped container

docker rm Removed a stopped container (delete it)

docker push / pull Share / Download a remote image

docker build Build a new image based on a Dockerfile

docker rmi Remove a local image


Module Summary

Docker is all about Images & Containers

Images are the templates / blueprints Images are either downloaded (docker
for Containers, multiple Containers can pull) or created with a Dockerfile and
be created based on one Image. docker build.

Images contain multiple layers (1 Containers are created with docker


Instruction = 1 Layer) to optimize build run IMAGE and can be configured with
speed (caching!) and re-usability various options / flags

Images can also be listed (docker


Containers can be listed (docker ps),
images), removed (docker rmi,
removed (docker rm) and stopped +
docker image prune) and shared
started (docker stop / start)
(docker push / pull)

You might also like