6
Dockerize Your Projects A Brief Introduction to Containerization Sawood Alam <@ibnesayeed> Old Dominion University, Norfolk, Virginia - 23529 (USA)

Dockerize Your Projects - A Brief Introduction to Containerization

Embed Size (px)

Citation preview

Page 1: Dockerize Your Projects - A Brief Introduction to Containerization

Dockerize Your ProjectsA Brief Introduction to Containerization

Sawood Alam <@ibnesayeed>Old Dominion University, Norfolk, Virginia - 23529 (USA)

Page 2: Dockerize Your Projects - A Brief Introduction to Containerization

Docker● Application container

● Packages dependencies

● Isolates applications

● Lighter than a virtual machine

● Open-source Host OS

Host OS

Docker Engine

Bins/Libs

App B

Bins/Libs

App A

Con

tain

er

Page 3: Dockerize Your Projects - A Brief Introduction to Containerization

Dockerization

Dockerfile ImageBuild Run Container

Page 4: Dockerize Your Projects - A Brief Introduction to Containerization

Example

#!/usr/bin/env python

import sysimport requestsfrom bs4 import BeautifulSoup

r = requests.get(sys.argv[-1])data = r.textsoup = BeautifulSoup(data)for link in soup.find_all("a"): print(link.get("href"))

FROM pythonLABEL maintainer="Sawood Alam <@ibnesayeed>"

RUN pip install beautifulsoup4RUN pip install requestsCOPY main.py /app/WORKDIR /appRUN chmod a+x main.py

ENTRYPOINT ["./main.py"]

main.py Dockerfile

Page 5: Dockerize Your Projects - A Brief Introduction to Containerization

Try Itme@thishost$ ls>> Dockerfile main.py# Build an image from the Dockerfile (change "ibnesayeed" with your Docker ID)me@thishost$ docker image build -t ibnesayeed/urlextractor .>> Layered docker images...# Run a container from the locally built imageme@thishost$ docker container run ibnesayeed/urlextractor https://odu.edu/compsci>> Extracted links…# Push the image to the registryme@thishost$ docker image push ibnesayeed/urlextractor# Log in to a different hostme@thishost$ ssh you@otherhost# Run a container on the other host using the image in the registryyou@otherhost$ docker container run ibnesayeed/urlextractor https://odu.edu/compsci>> Pull the image from the registry (if not cached already)>> Extracted links...