sh 利用nsenter进入码头工人容器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 利用nsenter进入码头工人容器相关的知识,希望对你有一定的参考价值。

#!/bin/sh



if [ -e $(dirname "$0")/nsenter ]; then

  # with boot2docker, nsenter is not in the PATH but it is in the same folder

  NSENTER=$(dirname "$0")/nsenter

else

  NSENTER=nsenter

fi



if [ -z "$1" ]; then

  echo "Usage: `basename "$0"` CONTAINER [COMMAND [ARG]...]"

  echo ""

  echo "Enters the Docker CONTAINER and executes the specified COMMAND."

  echo "If COMMAND is not specified, runs an interactive shell in CONTAINER."

else

  PID=$(docker inspect --format "{{.State.Pid}}" "$1")

  if [ -z "$PID" ]; then

    exit 1

  fi

  shift



  OPTS="--target $PID --mount --uts --ipc --net --pid --"



  if [ -z "$1" ]; then

    # No command given.

    # Use su to clear all host environment variables except for TERM,

    # initialize the environment variables HOME, SHELL, USER, LOGNAME, PATH,

    # and start a login shell.

    "$NSENTER" $OPTS su - root

  else

    # Use env to clear all host environment variables.

    "$NSENTER" $OPTS env --ignore-environment -- "$@"

  fi

fi

以上是关于sh 利用nsenter进入码头工人容器的主要内容,如果未能解决你的问题,请参考以下文章

sh 码头工人桥gwbridge群

sh 码头工人ip

sh Commandes码头工人

sh 清理码头工人aufs

sh 穷人码头工人堆栈解析器

sh 码头工人清理