Run Anything Anywhere

Why & What

  • No MORE Works On My Machine Excuses
  • If it can run on the host, it can run in the container
  • Easy to ship
  • Same environment for everyone
  • Not dependent on any machine environment
  • Lightweight VM
  • Own process space
  • Own Network space
  • Container is isolated process
  • Share kernel with HOST

VM Vs Docker

Docker Platform

Docker Engine

Docker Hub

1. Docker Daemon

2. Docker CLI

  • Provide services
  • Public/private Images
  • Registry
  • Ex. Harbor
  • Build Images
  • Manage containers
  • RESTful API
  • Through which we talk to daemon

Images

  • Class
  • Blueprint
  • Money making plate

Container

  • Object
  • Component
  • Money

Container is a run time instance of a docker image

Docker Layer Stack

Docker basic command

Dockerfile Keywords

FROM Image name after the keyword which to be a base image of yours. ex> FROM Nginx
ENV Environment variables for the image. i.e: NODE_ENV
WORKDIR Define the working directory
RUN Will executed when we `build`
EXPOSE Port to be exposed to the host
VOLUME Define shared volumes
CMD Will executed when `docker run`

Dockerfile

# SAMPLE Dockerfile

FROM nginx:latest
COPY ./index.html /usr/share/nginx/html/index.html

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
# Medium size Dockerfile
FROM node:10.15.3 as build-stage

RUN apt-get update && apt-get install -y jq python

WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install --frozen-lockfile --registry https://custom-registry
COPY . .
RUN yarn build

# Generate & Upload sourcemaps
RUN chmod 755 upload-sourcemap.sh
RUN ./upload-sourcemap.sh

# production stage
FROM nginx as production-stage

RUN rm /etc/nginx/conf.d/default.conf
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY nginx-conf/default.conf /etc/nginx/conf.d/

# Remove sourcemap from final image
RUN rm -rf /usr/share/nginx/html/js/*.map

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Docker Compose

Manage multiple containers/services at once

docker-compose.yml

version: "2"
services:
  redis:
      image: redis
      container_name: redis
      ports:
      - "6379:6379"

  bifrost:
    command: yarn dev -- -L
    links:
      - redis
    environment:
      - NODE_ENV=development
      - REDIS_URL=redis://redis

Volume & Network...

Shared files between containers

  • Through which containers talk
  • Bridge network by default docker maintain

References

NOTE: Took all the image in this slides taken from online

???

H

A

V

E

A

N

Y

Thanks

Docker Basics

By Emran Ul Hadi

Docker Basics

Docker is a lightweight virtual machine.

  • 42