Thursday, March 26, 2015

Docker: Design and Architecture

Modifying an Image


Let's say I pull an ubuntu image, add docker and want to commit this change:
sudo docker commit -m "added git" -a "Craig Trim" e50212abcd root/ubuntu:14.04

I can then launch one or more containers from this modified image using:
sudo docker run -t -i root/ubuntu:14.04 /bin/bash

as I normally would.


Local Storage on the Docker Host


Under this directory
/var/lib/docker

We have these contents:
root@dockerhost:/var/lib/docker# ls -lah
total 132K
drwxr-xr-x   5 root root 4.0K Jan 26 21:10 aufs
drwx------  22 root root 4.0K Mar 26 10:53 containers
drwx------   3 root root 4.0K Jan 26 21:10 execdriver
drwx------ 718 root root  72K Mar 26 10:43 graph
drwx------   2 root root 4.0K Jan 26 21:10 init
-rw-r--r--   1 root root  11K Mar 26 10:53 linkgraph.db
-rw-------   1 root root 4.6K Mar 26 10:43 repositories-aufs
drwx------   2 root root 4.0K Jan 26 21:10 tmp
drwx------   3 root root 4.0K Feb 16 08:31 vfs
drwx------   7 root root 4.0K Feb 17 17:30 volumes

Look at the repositories file using this command:
 cat repositories-aufs | python -mjson.tool | grep root/ubuntu -A 2

and the output is
"root/ubuntu": {
    "14.04": "24ca647184c90565dbb5a9009bcdcc030e814177e5a1cc8a4f14ef83d476b625"
}

This matches the output from running the "docker images" command:
root@dockerhost:/var/lib/docker# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
root/ubuntu         14.04               24ca647184c9        22 minutes ago      1.289 GB

The first 12 bytes of the IMAGE ID match the start of the key/value pair in the JSON list of local repositories.

By using the entirety of the ID, I can navigate to
root@dockerhost:/var/lib/docker/graph/24ca647184c90565dbb5a9009bcdcc030e814177e5a1cc8a4f14ef83d476b625# ls -lah
total 88K
-rw-------   1 root root 1.4K Mar 26 10:43 json
-rw-------   1 root root    9 Mar 26 10:43 layersize

and view the contents of the directory.

The "json" file contains metadata about the image:
{
    "Size": 956843450,
    "architecture": "amd64",
    "author": "Craig Trim",
    "comment": "adding hadoop provisioning",
    "config": {
        "AttachStderr": false,
        "AttachStdin": false,
        "AttachStdout": false,
        "Cmd": [
            "/bin/bash"
        ],
        "CpuShares": 0,
        "Cpuset": "",
        "Domainname": "",
        "Entrypoint": null,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        ],
        "ExposedPorts": null,
        "Hostname": "",
        "Image": "",
        "Memory": 0,
        "MemorySwap": 0,
        "NetworkDisabled": false,
        "OnBuild": null,
        "OpenStdin": false,
        "PortSpecs": null,
        "StdinOnce": false,
        "Tty": false,
        "User": "",
        "Volumes": null,
        "WorkingDir": ""
    },
    "container": "11ed9058054f2a5d58c28403f50234ebaa444cc08b185210754be74f46c5595a",
    "container_config": {
        "AttachStderr": true,
        "AttachStdin": true,
        "AttachStdout": true,
        "Cmd": [
            "/bin/bash"
        ],
        "CpuShares": 0,
        "Cpuset": "",
        "Domainname": "",
        "Entrypoint": null,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        ],
        "ExposedPorts": null,
 "Hostname": "11ed9058054f",
 "Image": "root/ubuntu:14.04",
 "Memory": 0,
 "MemorySwap": 0,
 "NetworkDisabled": false,
 "OnBuild": null,
 "OpenStdin": true,
 "PortSpecs": null,
 "StdinOnce": true,
 "Tty": true,
 "User": "",
 "Volumes": null,
 "WorkingDir": ""
    },
 "created": "2015-03-26T17:43:52.04299283Z",
 "docker_version": "1.2.0",
 "id": "24ca647184c90565dbb5a9009bcdcc030e814177e5a1cc8a4f14ef83d476b625",
 "os": "linux",
 "parent": "c9bd11fbe917e2855ed9872f4d05d216cbb1c3d5172fd542f6a479692b023004"
}





References

  1. [Blog] Beginner's Tutorial
    1. The idea behind Docker is to create portable lightweight containers for software applications that can be run on any machine with Docker installed
    2. Docker solves many of the same problem that a VM solves, plus some other that VMs could solve if they didn’t were so resource intensive.
    3. Here are some of the things that Docker can deal with:
      1. Isolating an application dependencies
      2. Creating an application image and replicating it
      3. Creating ready to start applications that are easily distributable
      4. Allowing easy and fast scalation of instances
      5. Testing out applications and disposing them afterwards
  2. [Blog] Where are Docker images stored?
    1. Local Storage on the Docker Host

No comments:

Post a Comment