Docker

Containers Vs. VMs

Image result for docker vs vm

Docker Image

  • It’s a template file from which Docker containers can be created.
  • Docker images are created with the build command, and this produces a container that starts when it is run.

Docker Hub

  • It’s a centralized resource for docker images where you to link to code repositories, build your images and test them, stores manually pushed images, and links to Docker cloud so you can deploy images to your hosts.
  • Docker images are stored in the Docker registry such as the public Docker registry (registry.hub.docker.com) as these are designed to be constituted with layers of other images, enabling just the minimal amount of data over the network.

Docker Container

  • Docker container is an isolated processes, which contains application and its dependencies, running on its own user space on a shared kernel (OS).
  • Docker containers are created out of Docker images.
  • Docker containers are basically runtime instances of Docker images.

Docker Client

  • Docker client is a CLI tool, which is nothing but HTTP API wrapped program.

Docker Daemon

  • When you use docker runcommand to start up a container, your docker client will translate that command into HTTP API call, sends it to docker daemon, Docker daemon then evaluates the request, talks to underlying OS and provisions your container.

Image result for Docker Daemon

Dockerfile 

  • Dockerfile is nothing but a set of build instructions that have to be passed on to Docker itself, so that it can build images automatically reading these instructions from that specified Dockerfile.
  • A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
FROM ubuntu:latest

RUN apt-get update
RUN apt-get install -y python python-pip wget
RUN pip install Flask

ADD hello.py /home/hello.py

WORKDIR /home

Docker Build

  • Build an image from a Dockerfile.
$ docker build -t "simple_flask:dockerfile" .

Docker Run

  • Run a command in a new container by using the docker image.
$ docker run -p 5000:5000 simple_flask:dockerfile python hello.py

dockerfile

Docker Inspect

  • Return low-level information on Docker objects
  • Example: Get an instance’s IP address

$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID

Docker pull, push, restart, stop, start

  • docker pull
    • Pull an image or a repository from a registry.
  • docker push
    • Push an image or a repository to a registry.
  • docker restart
    • Restarts the container.
  • docker start
    • Starts the stopped container.
  • docker stop
    • Stops the running container.

Docker Compose

  • Docker Compose is used to run multiple containers via single file called docker-compose.yml.
  • For example, suppose you had an application which required product-service and website, you could create one file which would start both the containers as a service without the need to start each one separately.
version: '3'
services:
  product-service:
    build: ./product
    ports:
     - "5001:80"
  website:
    image: php:apache
    ports:
     - "5000:80"
    depends-on:
     - product-service

Docker-compose start, up and run

All uses instructions from docker-compose.yml.

  • docker-compose start
    • Helps to restart the stopped containers.
  • docker-compose up
    • Helps to (re)-create containers and starts the new containers.
  • docker-compose run
    • Helps to build the images, (re)-create containers, starts and attaches to containers for a service.

docker_events

Docker Swarm

  • It’s an automatic orchestration tool (Docker cluster implementation) for Docker containers to scale your application running in clusters.
  • Docker Swarm turns a pool of Docker hosts into a single and virtual Docker host.
  • It serves the standard Docker API or any other tool that can already communicate with a Docker daemon can make use of Docker Swarm to scale in a transparent way to multiple hosts.

 

Leave a comment