MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers...

28
MSML 605 - Lecture 7 Containers

Transcript of MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers...

Page 1: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

MSML 605 - Lecture 7

Containers

Page 2: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Introduction

■ Containers

■ Separate applications and its dependencies.

■ Remove physical hardware requirements.

■ Docker is based on Linux containers

Page 3: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker Stack

Host Hardware

Host OS

Docker Engine

Application 1 Application 2 Application 3

Libraries Libraries Libraries

CONTAINER

Page 4: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker

■ Build an app once and run anywhere

■ Containers take fewer resources

■ Docker hub contains images available for use.

Page 5: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker Engine

■ To do anything with docker you need to install docker engine.

■ Get an OS specific image from https://docs.docker.com/get-docker/

■ To check that it is installed: docker —version

Docker Client

Docker Daemon

REST API

Page 6: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker Engine

■ To check that it is installed: docker —version

Page 7: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker Client

■ It is the user interface

■ You communicate with it.

■ It communicates with the Docker Daemon

Page 8: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker Daemon

■ It executes the commands you send to the client.

■ For example, building, running, and distributing your containers.

Page 9: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Dockerfile

■ It contains the instructions to build a Docker image.

■ For example, to install a software, set environmental variables etc.

■ Use docker build command to build an image from it.

■ Docker uses a Union file system.

■ Once you run the image it is a container

Page 10: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker Project - dockerApp

■ Python file: code.py

■ Requirements.txt file

Page 11: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Dockerfile

Page 12: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Dockerfile

■ FROM: get a parent image from the docker hubEach command int eh docker file uses this parent image.

■ Copy requirements file into the dockerApp folder

Page 13: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Dockerfile

■ Set dockerApp as the working directory ■ Run pip commands :

■ First to upgrade pip in the parent image ■ Second install all the dependencies in

requirements.txt in the parent image.

Page 14: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Dockerfile

■ Copy the app, code.py to the dockerApp

■ Define what command gets executed.

Page 15: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker Image

Page 16: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

List all local images

Page 17: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker hub

■ There is a container registry at Docker hub

■ 1 free private repository

■ Go to https://hub.docker.com/

■ Create a username followed by a new repository, msml605 (private)

Page 18: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker hub

■ <username>/msml605 (private)

■ Associate your image to this repository on docker hub

Page 19: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

List docker images

■ Associate your image to this repository on docker hub

■ docker image ls

Page 20: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Push local image to docker

■ You may need to login

Page 21: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker hub

■ There is a pull request

Page 22: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Docker hub

■ Run the remote image

■ Or pull from docker hub and run locally

Page 23: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Requirements file

■ Dependency manager — pipenv

■ Uses pip and virtualenv

■ For user installation

Page 24: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

Set up the PATH

■ vi ~/.bash_profile

■ In the terminal

Page 25: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

pipenv

Page 26: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

pipenv - shell to install packages

Page 27: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

pipenv - to install packages

Page 28: MSML 605 - Lecture 7 Containersnayeem/courses/MSML605/files/07_Containers.pdfIntroduction Containers Separate applications and its dependencies. Remove physical hardware requirements.

pipenv - requirements file