Getting Started with Docker

Docker

Docker

Docker provides the ability to package and run an application in a loosely isolated environment called container. The isolation and security allows you to run many containers simultaneously on a given host. Docker includes concept of versioned container repository so it is easy to keep track of changes.

Installing Docker on a machine gives your Docker Client and Daemon

Key Terminologies

  • Image - An organized collection of files, configuration and installed programs, as well as set of instructions as to how to execute those items.
  • Container - Running instance of Docker Image. Containers run the actual application. A container includes an application and all of its dependencies. It shares the kernel with other containers and runs as an isolated process in user space on the host OS.
  • Docker Daemon - The background service running on the host that manages building, running and distributing Docker containers.
  • Docker Client - The command line tool that allows the user to interact with Docker Daemon
  • Docker Store - Registry of Docker Images
  • Dockerfile - Text file that contains a list of commands that the Docker daemon calls when creating an image. Main set of instructions a User can execute to form a new Docker Image

Docker Container

  • A Docker container is a runnable instance of a Docker image. You can create, run, start, stop, move, or delete a container using Docker API or CLI commands.
  • Docker containers are the run components of Docker.
  • Container Lifecycle
    • docker create - Creates Container but does not start it
    • docker start - Starts a Container so it is running
    • docker run - Creates and Starts Container in on operation
    • docker stop - Stops a running Container
    • docker rm - Deletes Container
    • docker update - Update Container Resorce Limit

Docker Run - Running a Docker Container from Docker Image

Docker run is a docker client command. Client makes corresponding command to daemon to create a docker container from docker image.

# Syntax
docker run <image>

# Example
docker run hello-world

# Running Container in detached mode
docker run -d <image>

# Running Container in Interactive mode
docker run -it <image>

# Examples
docker run -p 8080:8080 -d art/trivianepal_api
docker run -it --name art-temp ubuntu:latest /bin/bash

Other Docker Container Commands

# List of Running Containers
docker container ls

# Stoping a Container
docker container stop <container>

# Removing a Container from List
docker container rm <container>

Docker Images

  • Docker Images are basis of containers
  • Base Image
    • Image that have no parent Image
  • Child Image
    • Image that build on base Image and Add Additional Functionality
# Pull Docker Image from Registry
docker pull <image>

# See List of Docker Images
docker images

# Create Docker Image from Dockerfile
docker build

# Building Image from Dockerfile
docker build -t <YOUR_USERNAME>/<imageName> .

Container and MicroServices

Microservices architecture is build on a principle of re-using REST based services. Microservices requires running small block of isolated code running in completed isolated environment. To facilitate this, Containers play a vital role to speed development and code deployment. With advent of microservices architecture, Containers have taken software deployment to whole new level. By providing the level of isolation required to run software within its own space, it has made much easier to deploy and tear down code rapidly. Containers are more resource efficient than full blown virtual machines.



Resources