Introduction To Containers: Nabil Abdennadher
Introduction To Containers: Nabil Abdennadher
Nabil Abdennadher
[email protected]
•1
Plan
• Introduction
• Details : chroot, control groups, namespaces
• My first container
• Deploying a distributed application using containers
•2
The pain
•3
Containers are the solution
•4
Virtualization vs.
“containerization”
•5
Virtualization vs.
“containerization”
• A virtual machine includes an entire operating system +
application.
• A physical server running three virtual machines would
have:
• a hypervisor,
• three separate operating systems running on top of it.
•6
Virtualization vs.
“containerization”
•7
What about security?
•8
Will containers eventually
replace virtualization?
•9
Plan
• Introduction
• Details : namespaces, control groups, chroot
• My first container
• Deploying a distributed application using containers
•10
•11
chroot
• Exists since 1979
• #include <unistd.h>
• int chroot(const char *path);
•12
Control groups (cgroups)
•13
Control groups (cgroups)
•14
Namespace
• A Linux installation:
• maintains a single process tree.
• shares a single set of network interfaces and routing table
entries.
• With namespaces, you can have different and separate
network interfaces and routing tables that operate
independent of each other: network namespace
• With namespaces, it became possible to have multiple
“nested” process trees. a process running within a
namespace can only see processes in the same
namespace: process namespace
•15
Process namespace
•https://www.toptal.com/linux/separation-anxiety-isolating-your-system-with-linux-namespaces
•16
Process namespace
•17
Process namespace (summary)
•18
Network namespace
•19
Network namespace
•20
Network namespace
•21
Plan
• Introduction
• Details : namespaces, control groups, chroot
• My first container (Docker)
• Deploying a distributed application using containers
•22
Docker
•23
Why Docker ?
•24
Creating your first
container with Docker
•25
Creating your first container
with Docker: server.py
• #!/bin/python
• from flask import Flask
• app = Flask(__name__)
• @app.route("/")
• def helloworld():
• return "Hello world !\n"
• app.run(host="0.0.0.0",debug=False)
•26
Creating your first
container with Docker
• Create a folder (example: dockertest)
• In dockertest folder, create Dockefile file
• FROM ubuntu:latest
• RUN apt-get update && apt-get
install -y python-pip
• RUN pip install flask
• COPY "server.py" "/tmp/server.py"
• EXPOSE 5000
• CMD ["python","/tmp/server.py"]
•27
Creating your first
container with Docker
•28
RUN, CMD, ENTRYPOINT
•29
RUN
•30
RUN
cvs \
git \
subversion
•31
CMD
•32
ENTRYPOINT
• Similar to CMD
• Used to transfer parameters (arguments) to the
container
•33
Plan
• Introduction
• Details : namespaces, control groups, chroot
• My first container (Docker)
• Deploying a distributed application using containers
•34
Docker installation
•35
restclient’s Dockerfile
• FROM ubuntu:latest
• RUN apt-get update && apt-get install -y
python-pip
• RUN pip install pymongo
• RUN pip install requests
• COPY "restclient.py" "/tmp/restclient.py”
• ENTRYPOINT ["python","/tmp/restclient.py”]
•36
restserver’s Dockerfile
• FROM ubuntu:latest
• RUN apt-get update && apt-get install -y
python-pip
• RUN pip install flask
• RUN pip install pymongoCOPY
"restserver.py" "/tmp/restserver.py”
• EXPOSE 18000
• ENTRYPOINT ["python","/tmp/restserver.py"]
•37
Deploying a distributed
applications with docker:
Creating images
• cd client
• docker build -t restclient .
• cd ../server
• docker build -t restserver .
•38