FEATURE: ./launcher enter <CONTAINER>
authorSam <sam.saffron@gmail.com>
Fri, 27 Jun 2014 05:57:12 +0000 (15:57 +1000)
committerSam <sam.saffron@gmail.com>
Fri, 27 Jun 2014 05:57:12 +0000 (15:57 +1000)
.gitignore
bin/.gitkeep [new file with mode: 0644]
image/nsenter/Dockerfile [new file with mode: 0644]
launcher

index 5497b2ca3b7d682f22d0fda2f604c60e5e4c0fc7..aa1d35fc5f4db9b57a694e05cb64725d871764c4 100644 (file)
@@ -2,3 +2,5 @@ shared/*
 *.swp
 containers/*
 cids/*
+bin/*
+image/nsenter/nsenter
diff --git a/bin/.gitkeep b/bin/.gitkeep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/image/nsenter/Dockerfile b/image/nsenter/Dockerfile
new file mode 100644 (file)
index 0000000..119e631
--- /dev/null
@@ -0,0 +1,5 @@
+# NOTE build nsenter locally
+# see: https://github.com/jpetazzo/nsenter
+
+FROM busybox
+ADD nsenter /nsenter
index 000641326c1de73187b7f56d2fcee3233bc800bd..0ef7680045117f14f5b946cea299dde3ec9b57ee 100755 (executable)
--- a/launcher
+++ b/launcher
@@ -30,6 +30,7 @@ usage () {
   echo "    stop:       Stop a running container"
   echo "    restart:    Restart a container"
   echo "    destroy:    Stop and remove a container"
+  echo "    enter:      Use nsenter to enter a container"
   echo "    ssh:        Start a bash shell in a running container"
   echo "    logs:       Docker logs for container"
   echo "    mailtest:   Test the mail settings in a container"
@@ -360,6 +361,35 @@ case "$command" in
       exit 0
       ;;
 
+  enter)
+
+      if [ ! -e $cidfile ]
+         then
+           echo "No cid found"
+           exit 1
+      fi
+
+      if [ ! $UID -eq 0 ] ;
+        then
+        echo "enter command must run as root, will attempt to sudo"
+        echo
+      fi
+
+      if [ ! -e bin/nsenter ]
+        then
+          echo "Downloading nsenter"
+          $docker_path pull samsaffron/nsenter
+          ($docker_path run --rm samsaffron/nsenter cat /nsenter > bin/nsenter1) || exit 1
+          cp bin/nsenter1 bin/nsenter
+          chmod +x bin/nsenter
+      fi
+
+      PID=$($docker_path inspect --format {{.State.Pid}} `cat $cidfile`)
+      SHELL=/bin/bash sudo -E bin/nsenter --target $PID --mount --uts --ipc --net --pid
+
+      exit 0;
+      ;;
+
   ssh)
       if [ ! -e $cidfile ]
          then