Giter Club home page Giter Club logo

container's Introduction

Container

A simple divertimento for understanding how containers work. This tool allows to execute a command in a very basic container environment.

Rootfs

Container expects to find a rootfs in some local path. One easy way to create a rootfs is by using debootstrap:

$ sudo apt update
$ sudo apt install debootstrap

For example, You can create a ubuntu bionic rootfs easily with:

$ sudo debootstrap --arch amd64 bionic /<a>/<path>

where /a/path points to a path in your local disk where placing the rootfs to be used into the container.

The container searches for the rootfs in the path declared in the file /etc/container/settings.yaml. You must create such file and provide the setttings:

rootfs: /<a>/<path>

Build

Configure go for giving it a go ;)

$ sudo apt install golang
$ echo 'export GOPATH=$HOME/go' >> ~/.bashrc
$ echo 'export PATH=${PATH}:${GOPATH}/bin' >> ~/.bashrc
$ source ~/.bashrc

Checkout and build container tool with:

$ go get -t github.com/rmescandon/container
$ go install -t github.com/rmescandon/container

Run

Setuid

Before launching the container, you need to do a trick for preventing to run it as root. You must set a flag in the file permissions for running the executable as the owner, and set root as the owner. That ways the OS thinks that root is launching the container and thus it is able to configure the network interfaces:

$ sudo chown root $GOBIN/container
$ sudo chmod +s $GOBIN/container

Launch

Launch container tool with:

$ $GOBIN/container run <list_of_commands_to_execute>

for example, listing the files in the rootfs:

$ $GOBIN/container run /bin/sh ls -la

or simply entering into the container for a further cli executions:

$ $GOBIN/container run /bin/sh

All those commands will be executed in a container environment, isolated (more or less) from host.

You can check that

  • container rootfs is at the settings configured path and host rootfs is not visible from within the container
  • ls -lah /proc/mounts reports only container mounts but not host's
  • ip link shows container interfaces but not the host's
  • id into the container is the root one, but does not have root permissions over the host
  • container hostname is different from the host one

Settings

Not only rootfs can be configured in the /etc/container/settings.yaml file but the bridge name, virtual devices or the bridge CIDR, like:

rootfs: /data/rootfs/bionic
network:
    bridge: thebridge
    veth : theveth
    cidr: 10.20.30.40/24

TBD

For now only mount, pid, user namespaces work. Network is in progress. It is possible to ping host ips, but not reaching internet from the container

Disclaimer

Tested on Ubuntu Bionic (18.04). This software is delivered as is. No support is provided.

container's People

Contributors

rmescandon avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.