Upgrade to Pro — share decks privately, control downloads, hide ads and more …

containwd.pdf

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Sowju Sowju
October 29, 2018
290

 containwd.pdf

Avatar for Sowju

Sowju

October 29, 2018
Tweet

Transcript

  1. Agenda • Background on how containers work • Overview of

    Docker • Docker containers, images & persistence • Hands-on practice • Multi container applications with docker-compose @gritncompassion
  2. OS Kernel vs User processes Kernel: • Is the first

    part of OS that is loaded into memory during system boot • Manages IPC and process management ( Manages hardware directly ) • Manages I/O, Memory • Interacts with underlying hardware User processes: • Interacts with Kernel using system calls (Manages hardware through the kernel) • Runs in the Userspace of the system @gritncompassion
  3. Container • Runs as a User process • replicate consistent

    environments for dev/staging/prod • easier to scale your app horizontally • run on any OS @gritncompassion
  4. What is docker? • Is a software which enables you

    to package an app and its dependencies together into an image • You can run multiple containers on the same machine and share the same kernel, each running an isolated process in the user space • cross-platform support for Mac, Windows, Linux @gritncompassion
  5. Workflow: Deploy a ruby on rails app In the past:

    • You downloaded ruby on your machine • You downloaded rails on your the machine • Make an app • Assume the machine you are deploying to, also has the same ruby version and rails version installed and then you can deploy a working app @gritncompassion
  6. Workflow: Deploy a ruby on rails app Now: • Get

    the docker image with ruby and rails installed with host OS • Create a new image with your app and the original image and deploy the new image @gritncompassion
  7. Docker images • Binary executable composed of the app and

    its dependencies based on Dockerfile • Docker images are made of layers Useful commands: • docker image ls • docker container ls –all @gritncompassion
  8. Dockerfile • Defines the components that will make up your

    new image for the app • FROM: • sets the base image for subsequent instructions; • a Dockerfile starts with a FROM instruction • Can appear multiple times within a single Dockerfile to create multiple images • ARG: to declare variables • WORKDIR: specifies the working directory for the subsequent RUN, CMD, COPY and ADD that follow it • ENV: is used to setup environment variables @gritncompassion
  9. Dockerfile • RUN: executes commands and outputs a new layer

    on top of an existing image and as a result creates a new image • EXPOSE: Specifies to the Docker Daemon that container listens on the specified port • CMD: Execute the command; only one per dockerfile • COPY: copies files, directories from src and adds them to the filesystem of the image @gritncompassion
  10. Dockerfile (EXPOSE) • https://docs.docker.com/engine/reference/builder/#expose • Publish all exposed ports(tcp/udp): docker

    run -P • port redirection: docker run –p ip:hostport:containerport • docker run –p 8000:80 • docker port <container> @gritncompassion
  11. Most used docker commands • docker –version • docker ps

    à list all running containers • docker ps –a à list all running and stopped containers • docker images • docker container –help • start • stop • rm • kill • ls • docker image –help • docker ports <container_name> @gritncompassion
  12. Building and running images • docker build –t <Image_name> .

    • docker run –it <images> /bin/bash • docker run -p 3000:3000 <image> @gritncompassion
  13. Practice • Go App • https://github.com/sowjumn/go-docker-test • Ruby App •

    https://github.com/sowjumn/ruby-docker-test • Node App • https://github.com/sowjumn/node-docker-test @gritncompassion
  14. Practice • Go to those apps and clone them (whichever

    language you are most comfortable in) • Build your docker image and run them • Try to Curl and see what you get • docker ps and look at the port mappings • docker stop to stop a container • docker start to start a container @gritncompassion
  15. Data Persistence: Volumes • Save & Read data from host

    machine by the container • Volumes : • managed by docker • can be created and managed outside the scope of a container • Mounts: • dependent on the directory structure of the host machine @gritncompassion
  16. Data Persistence: Practice • docker volume create test-volume • docker

    volume inspect test-volume • docker volume ls • docker volume prune @gritncompassion
  17. Docker compose • Run multi container docker applications • docker-compose.yml

    • describe the services for your app • docker-compose build • docker-compose up • docker-compose config @gritncompassion
  18. Docker compose • docker-compose run web rake db:create • docker-compose

    run web rake db:migrate • docker-compose up • docker-compose down @gritncompassion