Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2026537
  • 博文数量: 433
  • 博客积分: 918
  • 博客等级: 准尉
  • 技术积分: 3218
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 18:21
个人简介

你是不是暗恋我,那就给我发个消息呀,让我知道o(∩∩)o

文章分类

全部博文(433)

分类: LINUX

2017-08-18 17:56:19

 最近一直搞docker,老是用exec进入docker容器也很麻烦,今天在网上发现了nsenter进入容器很方便,解放了老是使用命令进入docker容器的麻烦,下面来看看nsenter的安装和使用吧.
  系统:centos 6.x(64位)
  环境:docker 1.7.1
1.安装nsenter
wget
tar zxf util-linux-2.24.tar.gz && cd util-linux-2.24
./configure --without-python --disable-all-programs --enable-nsenter --without-ncurses
make nsenter
cp nsenter /usr/local/bin

2.使用nsenter
cat docker-enter

点击(此处)折叠或打开

  1. #!/bin/sh
  2. if [ -e $(dirname "$0")/nsenter ]; then
  3.     # with boot2docker, nsenter is not in the PATH but it is in the same folder
  4.     NSENTER=$(dirname "$0")/nsenter
  5. else
  6.     NSENTER=nsenter
  7. fi
  8. if [ -z "$1" ]; then
  9.     echo "Usage: `basename "$0"` CONTAINER [COMMAND [ARG]...]"
  10.     echo ""
  11.     echo "Enters the Docker CONTAINER and executes the specified COMMAND."
  12.     echo "If COMMAND is not specified, runs an interactive shell in CONTAINER."
  13. else
  14.     PID=$(docker inspect --format "{{.State.Pid}}" "$1")
  15.     if [ -z "$PID" ]; then
  16.         exit 1
  17.     fi
  18.     shift
  19.     OPTS="--target $PID --mount --uts --ipc --net --pid --"
  20.     if [ -z "$1" ]; then
  21.         # No command given.
  22.         # Use su to clear all host environment variables except for TERM,
  23.         # initialize the environment variables HOME, SHELL, USER, LOGNAME, PATH,
  24.         # and start a login shell.
  25.         "$NSENTER" $OPTS su - root
  26.     else
  27.        # Use env to clear all host environment variables.
  28.        "$NSENTER" $OPTS env --ignore-environment -- "$@"
  29.     fi
  30. fi


阅读(2792) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~