• Stars
    star
    452
  • Rank 96,761 (Top 2 %)
  • Language
    C
  • License
    BSD Zero Clause L...
  • Created about 8 years ago
  • Updated about 2 years ago

Reviews

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

Repository Details

simple nsenter to namespaces of pid 1

nsenter1

Docker Build Status

Minimal image for nsenter to namespaces of PID 1

  • mnt
  • uts
  • net
  • ipc

To achieve the above with the basic alpine image you would enter:

$ docker run -it --rm --privileged --pid=host alpine:edge nsenter -t 1 -m -u -n -i sh
/ #

Unfortunately, however, there is an outstanding issue that prevents specifying the target pid.

With this image, you can simply run the following:

$ docker run -it --rm --privileged --pid=host justincormack/nsenter1
/ #

So what is this good for

nsenter allows you to enter a shell in a running container (technically into the namespaces that provide a container's isolation and limited access to system resources). The crazy thing is that this image allows you to run a privileged container that runs nsenter for the process space running as pid 1. How is this useful?

Well, this is useful when you are running a lightweight, container-optimized Linux distribution such as LinuxKit. Here is one simple example: say you want to teach a few people about Docker networking and you want to show them how to inspect the default bridge network after starting two containers using ip addr show; the problem is if you are demonstrating with Docker for Mac, for example, your containers are not running on your host directly, but are running instead inside of a minimal Linux OS virtual machine specially built for running containers, i.e., LinuxKit. But being a lightweight environment, LinuxKit isn't running sshd, so how do you get access to a shell so you can run nsenter to inspect the namespaces for the process running as pid 1?

Well, you could run the following:

$ screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty

Docker for Mac does expose a screen session to attach to, but it's a bit less than ideal if you're not familiar with screen. It's not a big deal, but it's not optimal and it's also very specific to Docker for Mac. Since we're already running Docker the general solution is ideal in this case:

$ docker run -it --rm --privileged --pid=host justincormack/nsenter1
/ # ip a
256: vethb72bfa3@if255: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue master docker0 state UP
    link/ether 7a:41:32:02:63:7c brd ff:ff:ff:ff:ff:ff
    inet6 fe80::7841:32ff:fe02:637c/64 scope link
       valid_lft forever preferred_lft forever
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 02:50:00:00:00:01 brd ff:ff:ff:ff:ff:ff
    inet 192.168.65.3/24 brd 192.168.65.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::49e8:1c10:4c64:c980/64 scope link
       valid_lft forever preferred_lft forever
...

Have fun!

More Repositories

1

ljsyscall

LuaJIT Unix syscall FFI
Lua
434
star
2

cross-docker

run docker containers for different architectures
Shell
68
star
3

go-memfd

Golang Linux memfd library
Go
67
star
4

frankenlibc

Tools for running rump unikernels in userspace
C
53
star
5

slice

Luajit array slice implementation
Lua
21
star
6

log4jpoc

Dockerfile
17
star
7

addmount

Mounts as file descriptors are useful
C
11
star
8

dockercommand-cli

Shell
11
star
9

luacparse-example

Example of using clang to parse and generate Lua bindings
Lua
11
star
10

libuntar

C library for reading tarfiles, stripped down version of libtar
C
7
star
11

does-github-support-ssh-signatures-yet

Does GitHub support git ssh signatures yet?
6
star
12

ljsyscall-examples

Examples of uses for ljsyscall
Lua
5
star
13

roadtounikernels

Talk from ContainerSched 2015
HTML
5
star
14

regextract

Docker hub file extraction tool
Go
4
star
15

alpine-pkgsrc-ocaml

Shell
4
star
16

pngback

PNGback - a javascript library for parsing PNG files
JavaScript
4
star
17

noise-gen

Noise pattern generator
Go
3
star
18

sign-index

Prototype of signing container images in the index
Go
3
star
19

netbsd-src

Cut down NetBSD source for rump kernels
C
2
star
20

rumprunqemu

2
star
21

rump-nginx-lua-test

Lua
2
star
22

alpine-pkgsrc

2
star
23

debian-pkgsrc

2
star
24

alpine-pbulk

Alpine pkgsrc configured for pbulk builds
2
star
25

alpine-qemu

alpine with qemu packages for docker
2
star
26

texaslinuxfest2015

Slides for Rump Unikernel workshop
HTML
2
star
27

multiarch-actions

Testing multiarch with Github Actions and Docker
Dockerfile
2
star
28

rump-redis

2
star
29

qconlondon2016

QCon London talk
HTML
2
star
30

lkl

lkl (Linux kernel library) Docker build
2
star
31

inotifywait

inotifywait docker container
1
star
32

test2

Just a test
Dockerfile
1
star
33

rumprun-nginx-lua

Makefile
1
star
34

rump-nginx-test

Lua
1
star
35

londonlua

London Lua user group website
CSS
1
star
36

rumprunqemu-nginx-lua-test

Lua
1
star
37

dockercontainer

1
star
38

inotify-tools

Docker build of inotify tools using Alpine
1
star
39

buildbot-netbsdhead

Buildbot config for rump kernel builds of NetBSD head
Python
1
star
40

rump-lua

Lua built for rump kernel
1
star
41

rump-nginx-lua

Lua
1
star
42

netlisten

C
1
star
43

rumprunxen-packages

1
star
44

fosdem2013

Fosdem lightning talk 2013: A high level language for low level code
JavaScript
1
star
45

rump-memcached

1
star
46

buildbot-rump

buildbot builds of the buildrump.sh repo
1
star
47

nixcfg

Nix config for test machine
Nix
1
star
48

murmer

shared library for murmer3 hash
C
1
star
49

rumprun-packages-hw_generic

1
star
50

rumpaio

experiments with Linux native aio for rump kernel block device
C
1
star
51

fuse-example

Example of fuse running in a container
Shell
1
star
52

rumprunxen

1
star
53

luawshop13

"Towards a scriptable operating system" talk for Lua Workshop 2013
JavaScript
1
star
54

snabbstack

IP stack for Snabb Switch
1
star
55

docker-debian

Useful install of Debian in docker
Dockerfile
1
star
56

docker-frankenlibc

Multi distro docker builds of frankenlibc
1
star
57

dockercon2016

Dockercon 2016 presentation
HTML
1
star
58

rumprunxen-nginx-lua-test

Lua
1
star
59

rumpfiber

Rump kernel hypercall library using fibers for threading
C
1
star