Docker Image:

Java Analogy: They are like your class file that you define in Java and at the end when the class file is running, it will be instanciated in the JVM. An instance of that class file is like a Docker Container.

A Docker Image is like a class file, but a container is the instance

What is a Docker Image?

  • An Image defines a Docker Container
    • Similar in concept to a snapshot of a VM
    • Or a class vs an instance of the class
  • Images are immutable
    • Once built, the files making up an image do not change

Image Layers

  • Images are built in layers
  • Each layer is an immutable file, but is a collection of files and directories
  • Layers received an ID, calculateed via a SHA 256 hash of the layer content
    • If the layer changes, the has changes

Image Ids

  • Image Ids are a SHA 256 hash derived from the layers
    • If the layer of the images changes, the SHA 256 hash changes
  • The Image ID listed by docker docker commands (id' docker images') is the first 12 characters of the hash.

Image Tag Names

  • The hash values of images can be assigned a human tag value reffered to by 'tag' names
    • Kind of an ip and domain name
  • The format of the full tag name is [REGISTRYHOST/[USERNAME/NAME|TAG}
  • For Regist Host 'registry.hub.docker.com' is inferred
  • For 'TAG' - lated is default and inferred

Docker Files

  • Recipe for the images
  • Each command you run in the docker file creates a new image layer
  • Docker Images can inherit from each other. Eg Mongo Image inherits from the Derbian Image

Non-Persisrence Storage

  • Docker images, all those layers are immutable except for one, the very last layer. This is how the database (Mongo) will persist storage
  • What happen when we bounce the container?
    • The data disappered
    • When the container went down, and came back up again , that last layer, got created as a new layer and attached to the container when started up
    • The old one went away, and a new one was allocated

Persistance Storage

What we want to do is assign storage (map to a specific directory) on the host for the container to use to persist the data

  • Eg Mongo command: $ docker run --name some-mongo -v /my/own/datadir:/data/db -d mongo:tag
docker run -p 5432:5432 -v /Users/ian/data/mongo:/data/db -d mongo 
-p means port mapping (Map my host post of 5432 to the container port 5432;
-d means daemon as to run as as dameon background  
-v means will map a directory in my machine (Users/ian/data) to the container directory of (data/db)

results matching ""

    No results matching ""