Dockerize Your Projects
A Brief Introduction to Containerization
Sawood Alam <@ibnesayeed>
Old Dominion University, Norfolk, Virginia - 23529 (USA)
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
Container
Dockerization
Dockerfile ImageBuild Run Container
Example
#!/usr/bin/env python
import sys
import requests
from bs4 import BeautifulSoup
r = requests.get(sys.argv[-1])
data = r.text
soup = BeautifulSoup(data)
for link in soup.find_all("a"):
print(link.get("href"))
FROM python
LABEL maintainer="Sawood Alam <@ibnesayeed>"
RUN pip install beautifulsoup4
RUN pip install requests
COPY main.py /app/
WORKDIR /app
RUN chmod a+x main.py
ENTRYPOINT ["./main.py"]
main.py Dockerfile
Try It
me@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 image
me@thishost$ docker container run ibnesayeed/urlextractor https://odu.edu/compsci
>> Extracted links…
# Push the image to the registry
me@thishost$ docker image push ibnesayeed/urlextractor
# Log in to a different host
me@thishost$ ssh you@otherhost
# Run a container on the other host using the image in the registry
you@otherhost$ docker container run ibnesayeed/urlextractor https://odu.edu/compsci
>> Pull the image from the registry (if not cached already)
>> Extracted links...
References
● https://www.docker.com/
● https://docs.docker.com/
● https://training.docker.com/
● http://training.play-with-docker.com/
● https://hub.docker.com/
● https://hub.docker.com/r/ibnesayeed/urlextractor/
● https://gist.github.com/ibnesayeed/b4b069b8007f68be91a179a099e35d71

Dockerize Your Projects - A Brief Introduction to Containerization

  • 1.
    Dockerize Your Projects ABrief Introduction to Containerization Sawood Alam <@ibnesayeed> Old Dominion University, Norfolk, Virginia - 23529 (USA)
  • 2.
    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 Container
  • 3.
  • 4.
    Example #!/usr/bin/env python import sys importrequests from bs4 import BeautifulSoup r = requests.get(sys.argv[-1]) data = r.text soup = BeautifulSoup(data) for link in soup.find_all("a"): print(link.get("href")) FROM python LABEL maintainer="Sawood Alam <@ibnesayeed>" RUN pip install beautifulsoup4 RUN pip install requests COPY main.py /app/ WORKDIR /app RUN chmod a+x main.py ENTRYPOINT ["./main.py"] main.py Dockerfile
  • 5.
    Try It me@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 image me@thishost$ docker container run ibnesayeed/urlextractor https://odu.edu/compsci >> Extracted links… # Push the image to the registry me@thishost$ docker image push ibnesayeed/urlextractor # Log in to a different host me@thishost$ ssh you@otherhost # Run a container on the other host using the image in the registry you@otherhost$ docker container run ibnesayeed/urlextractor https://odu.edu/compsci >> Pull the image from the registry (if not cached already) >> Extracted links...
  • 6.
    References ● https://www.docker.com/ ● https://docs.docker.com/ ●https://training.docker.com/ ● http://training.play-with-docker.com/ ● https://hub.docker.com/ ● https://hub.docker.com/r/ibnesayeed/urlextractor/ ● https://gist.github.com/ibnesayeed/b4b069b8007f68be91a179a099e35d71