Docker fundamentals

Nowadays everybody is talking about Docker. Some people are well versed with docker concepts and have hands on it and some have started learning docker.

So what is Docker?

As per the official docs from docker, Docker is a platform for developers and sysadmins to develop, deploy, and run applications with containers.

So what does make it different. We were already doing that since long.

When we are deploying application on servers we have to deal with setting up new VM, configuring dependencies / libraries, environment variables. Docker makes this thing easy for you, by providing OS level virtualization (aka. containerization). So basically you can create Docker images that will have all your resources ( env. variables / libs / running on what port). Then you can deploy your application inside docker container anywhere without even worrying about the dependencies.

In traditional way you have to setup separate VM and then install all the required software and have all the dependencies in place , set the env variables. After doing all these sysadmin tasks then only you can deploy your application inside that VM.

Docker Architecture:

Docker architecture

Installation details: 

You can download docker community edition from docker - community-edition. Then install it as per the docker guide.

Docker Basic Commands:

  • docker version:
  • Used to check the docker version. (Client and server).
    C:\Users\DELL>docker version
    Client:
     Version:       17.12.0-ce
     API version:   1.35
     Go version:    go1.9.2
     Git commit:    c97c6d6
     Built: Wed Dec 27 20:05:22 2017
     OS/Arch:       windows/amd64
    
    Server:
     Engine:
      Version:      17.12.0-ce
      API version:  1.35 (minimum version 1.12)
      Go version:   go1.9.2
      Git commit:   c97c6d6
      Built:        Wed Dec 27 20:12:29 2017
      OS/Arch:      linux/amd64
      Experimental: true
    
  • docker info:
  • Used to display system wide information. It includes kernel version, no of containers and images inside docker enviornment.
    C:\Users\DELL>docker info
    Containers: 9
     Running: 4
     Paused: 0
     Stopped: 5
    Images: 13
    Server Version: 17.12.0-ce
    Storage Driver: overlay2
     Backing Filesystem: extfs
     Supports d_type: true
     Native Overlay Diff: true
    Logging Driver: json-file
    Cgroup Driver: cgroupfs
    Plugins:
     Volume: local
     Network: bridge host ipvlan macvlan null overlay
     Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
    Swarm: inactive
    Runtimes: runc
    Default Runtime: runc
    Init Binary: docker-init
    containerd version: 89623f28b87a6004d4b785663257362d1658a729
    runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f
    init version: 949e6fa
    Security Options:
     seccomp
      Profile: default
    Kernel Version: 4.9.60-linuxkit-aufs
    Operating System: Docker for Windows
    OSType: linux
    Architecture: x86_64
    CPUs: 2
    Total Memory: 1.934GiB
    Name: linuxkit-00155d123c0b
    ID: BHUM:UVFR:XJUC:G7LT:Y2CX:76UL:JUBA:Q67S:2T4W:SQ6M:CLCR:NOX3
    Docker Root Dir: /var/lib/docker
    Debug Mode (client): false
    Debug Mode (server): true
     File Descriptors: 36
     Goroutines: 66
     System Time: 2018-03-19T11:14:08.4256156Z
     EventsListeners: 1
    Registry: https://index.docker.io/v1/
    Labels:
    Experimental: true
    Insecure Registries:
     127.0.0.0/8
    Live Restore Enabled: false
    
  • docker run imagename:
  • It first check whether your machine already have that docker image. If not found then it will download the same from docker repository and will run inside docker container.
    C:\Users\DELL>docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    ca4f61b1923c: Pull complete
    Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
        (amd64)
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
     https://cloud.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/engine/userguide/
    
  • docker rmi imagename:
  • To remove specific docker images from your machine. If your image has been used by any docker container (running instance of image) it will throw an error.
    C:\Users\DELL>docker rmi hello-world
    Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container f643045cfa75 is using its referenced image f2a91732366c
    
    // To check all the containers
    C:\Users\DELL>docker ps -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                    NAMES
    f643045cfa75        hello-world         "/hello"                 5 minutes ago       Exited (0) 5 minutes ago                             awesome_khorana
    
    // To forcefully remove the image
    C:\Users\DELL>docker rmi -f hello-world
    Untagged: hello-world:latest
    Untagged: hello-world@sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
    Deleted: sha256:f2a91732366c0332ccd7afd2a5c4ff2b9af81f549370f7a19acd460f87686bc7
    
  • docker inspect repositoryName:
  • To get the detailed information about docker repository such as author of the repository, O.S, size, Config element if any.
    C:\Users\DELL>docker inspect hello-world
    [
        {
            "Id": "sha256:f2a91732366c0332ccd7afd2a5c4ff2b9af81f549370f7a19acd460f87686bc7",
            "RepoTags": [
                "hello-world:latest"
            ],
            "RepoDigests": [
                "hello-world@sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1"
            ],
            "Parent": "",
            "Comment": "",
            "Created": "2017-11-21T00:23:18.797567713Z",
            "Container": "fb0b4536aac3a96065e1bedb2b637a6019feec666c7699592206956c9d3adf5f",
            "ContainerConfig": {
                "Hostname": "fb0b4536aac3",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                ],
                "Cmd": [
                    "/bin/sh",
                    "-c",
                    "#(nop) ",
                    "CMD [\"/hello\"]"
                ],
                "ArgsEscaped": true,
                "Image": "sha256:2243ee460b69c4c036bc0e42a48eaa59e82fc7737f7c9bd2714f669ef1f8370f",
                "Volumes": null,
                "WorkingDir": "",
                "Entrypoint": null,
                "OnBuild": null,
                "Labels": {}
            },
            "DockerVersion": "17.06.2-ce",
            "Author": "",
            "Config": {
                "Hostname": "",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                ],
                "Cmd": [
                    "/hello"
                ],
                "ArgsEscaped": true,
                "Image": "sha256:2243ee460b69c4c036bc0e42a48eaa59e82fc7737f7c9bd2714f669ef1f8370f",
                "Volumes": null,
                "WorkingDir": "",
                "Entrypoint": null,
                "OnBuild": null,
                "Labels": null
            },
            "Architecture": "amd64",
            "Os": "linux",
            "Size": 1848,
            "VirtualSize": 1848,
            "GraphDriver": {
                "Data": {
                    "MergedDir": "/var/lib/docker/overlay2/61badba77bc2c48ceb5aefd993a293f1335c962a976c600b8c42dbcb513140fe/merged",
                    "UpperDir": "/var/lib/docker/overlay2/61badba77bc2c48ceb5aefd993a293f1335c962a976c600b8c42dbcb513140fe/diff",
                    "WorkDir": "/var/lib/docker/overlay2/61badba77bc2c48ceb5aefd993a293f1335c962a976c600b8c42dbcb513140fe/work"
                },
                "Name": "overlay2"
            },
            "RootFS": {
                "Type": "layers",
                "Layers": [
                    "sha256:f999ae22f308fea973e5a25b57699b5daf6b0f1150ac2a5c2ea9d7fecee50fdf"
                ]
            },
            "Metadata": {
                "LastTagTime": "0001-01-01T00:00:00Z"
            }
        }
    ]
    
    In this post we have seen the basic understanding of docker container and concepts around docker ecosystem. We have also seen docker basic commands. In the next post we will touch different features and the commands of working with docker container.

Cookies Consent

This website uses cookies to offer you a better Browsing Experience. By using our website, You agree to the use of Cookies

Privacy Policy