• Stars
    star
    794
  • Rank 57,305 (Top 2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Docker-type runtime, written in 100% Python

mocker

A proof-of-concept imitation of Docker, written in 100% Python. Using Kernel Namespaces, cgroups and network namespaces/iproute2 for Linux.

Why?

I keep hearing statements like "Docker is basically just cgroups", "Docker is just chroot on steroids", which is totally incorrect.

I'm giving a talk at the Sydney Docker meetup on the 18th October about some of the core concepts in Kernel namespaces, cgroups and network namespaces and fancied a simple implementation to show how container isolation works, the docker image format (the new API) and also how much more there is to Docker than those core kernel features.

Caveats

  1. I wrote this in 2 days, don't take it seriously
  2. This will only work on Linux, tested on CentOS 7 and Ubuntu 14.
  3. Try out the nginx container
  4. My networking implementation is half-finished, still need to figure out the NAT'ing.
  5. I tried some images and had problems with their start commands, I must be layering the stack incorrectly. It does chroot on the squashed image download instead of using a btrfs snapshot mount.

mocker pull

Mocker pull will download a Docker image from the Docker public repository, download the image layers and extract them into a local folder.

./mocker.py pull hello-world
Starting new HTTPS connection (1): auth.docker.io
Setting read timeout to None
"GET /token?service=registry.docker.io&scope=repository:library/hello-world:pull HTTP/1.1" 200 1450
Fetching manifest for hello-world:latest...
Starting new HTTPS connection (1): registry-1.docker.io
Setting read timeout to None
"GET /v2/library/hello-world/manifests/latest HTTP/1.1" 200 2750
Fetching layer sha256:c04b14da8d1441880ed3fe6106fb2cc6fa1c9661846ac0266b8a5ec8edf37b7c..
Starting new HTTPS connection (1): registry-1.docker.io
Setting read timeout to <object object at 0x7fabadba50b0>
"GET /v2/library/hello-world/blobs/sha256:c04b14da8d1441880ed3fe6106fb2cc6fa1c9661846ac0266b8a5ec8edf37b7c HTTP/1.1" 307 432
Starting new HTTPS connection (1): dseasb33srnrn.cloudfront.net
Setting read timeout to <object object at 0x7fabadba50b0>
"GET /registry-v2/docker/registry/v2/blobs/sha256/c0/c04b14da8d1441880ed3fe6106fb2cc6fa1c9661846ac0266b8a5ec8edf37b7c/data?Expires=1476758515&Signature=P~1JaRJM6u9SNOq9c8MTsie5cEN4HPixwAKza2FPGnXu85au4r0fcbUhRWFnENHyTR1ntlYajARBIbelKb4Yf92OTFyVum~hKmOs3fXz7dCTRLNQDJ6iCuGZG1apqQ7j4JJLqP8bnkIe40FZ6WbYxG3pYqv2s0lxsdsFytgvCm0_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q HTTP/1.1" 200 974
- hello
...
Fetching layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4..
Starting new HTTPS connection (1): registry-1.docker.io
Setting read timeout to <object object at 0x7fabadba50b0>
"GET /v2/library/hello-world/blobs/sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4 HTTP/1.1" 307 432
Starting new HTTPS connection (1): dseasb33srnrn.cloudfront.net
Setting read timeout to <object object at 0x7fabadba50b0>
"GET /registry-v2/docker/registry/v2/blobs/sha256/a3/a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4/data?Expires=1476758516&Signature=CkRP6ohZMxL5OJ5pX9Oamsds5oP8AEafk0otQo4Udd21DA5SparSxSlJSR7JxXkF16BS8X2kdbVGxdJxehNHCsvb~Z2dIVyA9Vrr6XKgAfmgfP2prt2GixMJzi0HZDut8DRgSK57qlzvGlYRmeKL-pk5q1HCEEgwmHoTnW450NY_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q HTTP/1.1" 200 32
...

mocker image

Mocker images will show you which images you've already downloaded

./mocker.py images
+------------------+---------+----------+-----------------------+
| name             | version | size     | file                  |
+------------------+---------+----------+-----------------------+
| library/tomcat   | latest  | 153.9MiB | library_tomcat.json   |
| library/rabbitmq | latest  | 82.6MiB  | library_rabbitmq.json |
+------------------+---------+----------+-----------------------+

mocker run

Mocker run will

  • Create a veth0 bridge virtual ethernet adapter in the root namespace
  • Create a network namespace for the "container"
  • Bridge a veth1 adapter into the new network namespace under the IP 10.0.0.3/24
  • Setup a default route for 10.0.0.1
  • Create a cgroup for the processes
  • ChRoot to the extracted image directory - no snapshots (yet) which is bad
  • Execute the docker image's chosen Cmd, setup environment variables and write the output to /tmp/stdout
./mocker.py run library/hello-world
Creating cgroups sub-directories for user root
Hierarchies availables: ['hugetlb', 'perf_event', 'blkio', 'devices', 'memory', 'cpuacct', 'cpu', 'cpuset', 'freezer', 'systemd']
cgroups sub-directories created for user root
Creating cgroups sub-directories for user root
Hierarchies availables: ['hugetlb', 'perf_event', 'blkio', 'devices', 'memory', 'cpuacct', 'cpu', 'cpuset', 'freezer', 'systemd']
cgroups sub-directories created for user root
Running "/hello"
Creating cgroups sub-directories for user root
Hierarchies availables: ['hugetlb', 'perf_event', 'blkio', 'devices', 'memory', 'cpuacct', 'cpu', 'cpuset', 'freezer', 'systemd']
cgroups sub-directories created for user root
Setting ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

None
None
Finalizing
done

TODO

The other 99.999% of Docker. I only had 2 days to write this!

More Repositories

1

vscode-pets

Adds playful pets 🦀🐱🐶 in your VS Code window
TypeScript
1,553
star
2

wily

A Python application for tracking, reporting on timing and complexity in Python code
Python
1,205
star
3

perflint

Python Linter for performance anti patterns
Python
582
star
4

pycharm-security

Finds security holes in your Python projects from PyCharm and GitHub
Kotlin
312
star
5

cpython-book-samples

Sample scripts and examples for my CPython Internals book
Python
180
star
6

anti-patterns

Python
137
star
7

instaviz

Instant visualization of Python AST and Code Objects
JavaScript
107
star
8

rich-bench

A little benchmarking tool for Python
Python
100
star
9

retox

For running a local continuous testing environment with tox
Python
76
star
10

ants-azure-demos

Collection of PoCs and Azure Demos
Python
49
star
11

python-assembly-poc

Python
46
star
12

requests-staticmock

A test utility for mocking out requests host from a fixtures directory
Python
42
star
13

django-xss-fuzzer

An XSS fuzzer for Django
Python
38
star
14

workday

A Python client for workday.com
Python
37
star
15

CSnakes

C#
37
star
16

azure-pipelines-python-examples

Example configurations for Azure Build Pipelines for Python
Python
36
star
17

hathi

A dictionary attack tool for PostgreSQL and MSSQL
Python
33
star
18

pep-explorer

An easy to use online explorer for Python Enhancement Proposals
HTML
33
star
19

notations

Estimating Big-O notations for a given function in Python
Python
24
star
20

django-on-azure

Resources for my Django on Azure workshop at PyCon US 2021
CSS
19
star
21

ServiceNowHackathon2016

Sydney Hackathon with ServiceNow March 2016- Slack and ServiceNow
JavaScript
19
star
22

tonybaloney.github.io

HTML
19
star
23

wntf

An anti-recommendation algorithm for twitter
Python
17
star
24

pyucwa

Python client for the Skype for Business (Lync) UCWA 2.0 API
Python
17
star
25

django-on-azure-demo

Tutorial for running Django on Azure
Python
16
star
26

dependabot-bot

Python
15
star
27

sciencelogic

A ScienceLogic EM7 API client for Python
Python
15
star
28

readysalted

An Internet of Things toolkit for SaltStack
C++
14
star
29

hubot-spark

A hubot integration for Cisco Spark
CoffeeScript
14
star
30

dissy

A TUI disassembler
Python
14
star
31

pyinline

Python
13
star
32

St2Client

A StackStorm API client for C#.NET including a PowerShell module
C#
13
star
33

python-railroads

A script to generate railroad diagrams for Python grammar
Python
13
star
34

tonybaloney

12
star
35

netimages

tool for sniffing images over HTTP traffic and showing them on the console. Designed for remote shells.
Python
12
star
36

bad-security-practices

Python
11
star
37

performance_testing

Results from a performance test for Python runtimes
HTML
9
star
38

try-pyjion

JavaScript
8
star
39

confluence-to-powerpoint

Python
8
star
40

generic_demos

Python
7
star
41

python-3.11-demos

Python
6
star
42

libcloud.extra

Some extra packs and examples for libcloud integration with StackStorm
Python
6
star
43

python-task-provider

TypeScript
5
star
44

pluralsight

Python
5
star
45

markdownlint-rule-titlecase

Custom title case rule for markdownlint headers
JavaScript
4
star
46

wily-pycharm

Code Complexity Plugin for PyCharm and IntelliJ-based IDEs
Kotlin
4
star
47

multicloud

Python
4
star
48

pytest-freethreaded

Python
4
star
49

pyrower

A Python Rowing Machine
Python
3
star
50

django-cosmos

A Cosmos DB driver for Django
Python
3
star
51

vs-test-detail

An NUnit extension for Azure DevOps
TypeScript
3
star
52

Cloud-auto-scaling

Provides auto-scaling capabilities to a group of Virtual Servers via SNMP, currently works with Abiquo
PHP
3
star
53

python-for-csharp-java-devs

2
star
54

pywinexe

Python bindings for winexe
Python
2
star
55

rightscale-agent-libcloud

Python
2
star
56

pathgather

Python client for Pathgather API
Python
2
star
57

pyjion-home

The website for www.trypyjion.com
CSS
2
star
58

tox-nuitka

A tox plugin for executing via nuitka
Python
2
star
59

cpython-clion-demo

Demo of debugging CPython from CLion
C
2
star
60

simple-flask-azd

A tiny template for Azure Developer CLI with Flask running in App Service
Bicep
1
star
61

email-toolbox

Python
1
star
62

panic_room

Python
1
star
63

pysaba

Python
1
star
64

cisco-spark-async-bot

A Python Asynchronous Bot for Cisco Spark API
Python
1
star
65

hubot-servicenow

JavaScript
1
star
66

ants-vscode-session

Jupyter Notebook
1
star
67

Abiquo-Backup

Backup Virtual Machines in an Abiquo Cloud
PHP
1
star
68

cognitive-kitchen-sink

SCSS
1
star
69

No-More-Spreadsheets

A web based service catalogue and pricing tool for products and services.
ASP
1
star
70

PHPVarnish

PHP Class for Varnish Management CLI
PHP
1
star
71

pycharm-webinar

Demo project for PyCharm webinar
Python
1
star
72

pyupgradesim

CSS
1
star