zoukankan      html  css  js  c++  java
  • 如何进入指定docker容器的namespace?

    脚本如下:

    #!/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: docker-enter.sh 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
    
  • 相关阅读:
    GC原理知多少
    C# 编译运行原理
    NetCore无需添加web/wcf引用来调用webservice
    WPF基础知识-资源概述
    WPF基础知识-XAML概述
    WPF入门-使用C#创建简单应用
    WPF概述
    Entity Framework Core
    Entity Framework Core
    Entity Framework Core
  • 原文地址:https://www.cnblogs.com/futuretea/p/11996189.html
Copyright © 2011-2022 走看看