Code Monkey home page Code Monkey logo

dockerself's Introduction

dockerself

🐳 runtime dockerizer

This is a PoC of a go program that calls the Docker API, inject itself (the binary) and switch to Docker for the execution.

It's like syscall.Exec within Docker.

⚠️ the injected binary will run within Docker, so it must be build for the same architecture and should be build statically. (a.k.a. it works well on Linux).

Usage

import (
        "flag"
        "fmt"

        "moul.io/dockerself"
)

func main() {
        dockerize := flag.Bool("dockerize", false, "dockerize")
        flag.Parse()
	    if *dockerize {
		        dockerself.Dockerize("ubuntu")
                return
		}
        if dockerize.WithinDocker() {
                fmt.Println("I'm inside the matrix (docker)")
        } else {
                fmt.Println("I'm in the real world :(")
        }
}
$ ./example
I'm in the real world :(
$ ./example --dockerize
I'm inside the matrix (docker)

Example

See dockerself-example.

# go get moul.io/dockerself/dockerself-example
# dockerself-example
within docker: false
env: [XDG_SESSION_ID=93 SHELL=/bin/bash TERM=screen SSH_CLIENT=82.254.90.14 50450 22 SSH_TTY=/dev/pts/0 LC_ALL=en_US.UTF-8 USER=moul ...]
starting interactive `/bin/sh` session...
$ ls -la
total 20
drwxrwxr-x 2 moul moul 4096 Feb 14 16:48 .
drwxrwxr-x 7 moul moul 4096 Feb 14 16:48 ..
-rw-rw-r-- 1 moul moul   95 Feb 14 16:48 go.mod
-rw-rw-r-- 1 moul moul 2578 Feb 14 16:48 go.sum
-rw-rw-r-- 1 moul moul  348 Feb 14 16:48 main.go
$
# dockerself-example  --dockerize
within docker: true
env: [PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=72a73eaf8cbb TERM=xterm HOME=/root]
starting interactive `/bin/sh` session...
$ ls -la
total 10492
drwxr-xr-x  33 root root     4096 Feb 14 15:50 .
drwxr-xr-x  33 root root     4096 Feb 14 15:50 ..
-rwxr-xr-x   1 root root        0 Feb 14 15:50 .dockerenv
drwxr-xr-x   2 root root     4096 Feb  4 21:05 bin
drwxr-xr-x   2 root root     4096 Apr 24  2018 boot
drwxr-xr-x   5 root root      360 Feb 14 15:50 dev
-rwxr-xr-x   1 root root 10667575 Jan  1  1970 dockerself
drwxr-xr-x  31 root root     4096 Feb 14 15:50 etc
drwxr-xr-x   2 root root     4096 Apr 24  2018 home
drwxr-xr-x   8 root root     4096 May 23  2017 lib
drwxr-xr-x   2 root root     4096 Feb  4 21:03 lib64
drwxr-xr-x   2 root root     4096 Feb  4 21:02 media
drwxr-xr-x   2 root root     4096 Feb  4 21:02 mnt
drwxr-xr-x   2 root root     4096 Feb  4 21:02 opt
dr-xr-xr-x 266 root root        0 Feb 14 15:50 proc
drwx------   2 root root     4096 Feb  4 21:04 root
drwxr-xr-x   5 root root     4096 Feb  6 03:37 run
drwxr-xr-x   2 root root     4096 Feb  6 03:37 sbin
drwxr-xr-x   2 root root     4096 Feb  4 21:02 srv
dr-xr-xr-x  13 root root        0 Oct 13 20:12 sys
drwxrwxrwt   2 root root     4096 Feb  4 21:05 tmp
drwxr-xr-x  11 root root     4096 Feb  4 21:02 usr
drwxr-xr-x  13 root root     4096 Feb  4 21:04 var
$
container exited.
#

dockerself's People

Contributors

moul avatar

Stargazers

Thugger069 avatar  avatar idk avatar moul-bot avatar PiereLucas avatar  avatar Abasi-amefon Affia avatar Muhammad Yuga N. avatar Madhu Akula avatar ktx avatar Doru Carastan avatar  avatar Hüseyin DEMİRTAŞ avatar Gerardo Malpartida avatar Diliz avatar  avatar Henry Wallace avatar Giacomo Guiulfo avatar Roy Hvaara avatar Quentin Perez avatar Solvik avatar Caleb Jasik avatar

Watchers

 avatar James Cloos avatar  avatar

dockerself's Issues

Why?

Really cool tech, pretty amazing that this can work! Just wondering, what did you originally build this for?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

gomod
go.mod

  • Check this box to trigger a request for Renovate to run again on this repository

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.