【问题标题】:Run Omnet++ inside docker with x11 forwarding on windows. SSH not working在 Windows 上使用 x11 转发在 docker 内运行 Omnet++。 SSH 不工作
【发布时间】:2017-06-23 14:02:38
【问题描述】:

无法 ssh 进入在 Windows 主机上运行的容器

对于一个大学项目,我构建了一个包含 Omnet++ 的 docker 映像,以提供一致的开发环境。

Image 使用 phusions 的 Baseimage 并通过 SSH 设置 x11 转发,就像 rogaha 在他的 docker-desktop 图像中所做的那样。

该映像在 Linux 主机系统上运行良好。但在 Windows 和 OS X 上,我无法从主机对容器进行 ssh。

我认为这是由于 Docker 在 Windows 和 OS X 上的不同实现。正如 Microsoft Docker 在this 文章中所解释的那样,默认使用容器的 NAT 网络将网络与主机和容器分开。


我的问题是我不知道如何通过 ssh 访问正在运行的容器。 我已经尝试了以下方法:

  • 如 Microsoft 文章中所述,将容器网络更改为透明网络。在 Windows 和 OS X 中都会出现以下错误:
docker network create -d transparent MyTransparentNetwork
Error response from daemon: legacy plugin: plugin not found
  • 在 Windows 上,在 Virtualbox 而不是 Hyper-V 中运行 Docker
  • 像这样显式暴露端口 22:
docker run -p 52022:22 containerName
ssh -p 52022 root@ContainerIP 

Dockerfile

FROM phusion/baseimage:latest
MAINTAINER Robin Finkbeiner 
LABEL Description="Docker image for Nesting Stupro University of Stuttgart containing full omnet 5.1.1"

# Install dependencies
RUN apt-get update && apt-get install -y \
    xpra\
    rox-filer\
    openssh-server\
    pwgen\
    xserver-xephyr\
    xdm\
    fluxbox\
    sudo\
    git \
    xvfb\
    wget \
    build-essential \
    gcc \
    g++\
    bison \
    flex \
    perl \
    qt5-default\
    tcl-dev \
    tk-dev \
    libxml2-dev \
    zlib1g-dev \
    default-jre \
    doxygen \
    graphviz \
    libwebkitgtk-3.0-0 \
    libqt4-opengl-dev \
    openscenegraph-plugin-osgearth \
    libosgearth-dev\
    openmpi-bin\
    libopenmpi-dev

# Set the env variable DEBIAN_FRONTEND to noninteractive
ENV DEBIAN_FRONTEND noninteractive

#Enabling SSH -- from phusion baseimage documentation 
RUN rm -f /etc/service/sshd/down

# Regenerate SSH host keys. baseimage-docker does not contain any, so you
# have to do that yourself. You may also comment out this instruction; the
# init system will auto-generate one during boot.
RUN /etc/my_init.d/00_regen_ssh_host_keys.sh

# Copied command from https://github.com/rogaha/docker-desktop/blob/master/Dockerfile
# Configuring xdm to allow connections from any IP address and ssh to allow X11 Forwarding. 
RUN sed -i 's/DisplayManager.requestPort/!DisplayManager.requestPort/g' /etc/X11/xdm/xdm-config
RUN sed -i '/#any host/c\*' /etc/X11/xdm/Xaccess
RUN ln -s /usr/bin/Xorg 
RUN echo X11Forwarding yes >> /etc/ssh/ssh_config

# OMnet++ 5.1.1

# Create working directory
RUN mkdir -p /usr/omnetpp
WORKDIR /usr/omnetpp

# Fetch Omnet++ source
RUN wget https:******omnetpp-5.1.1-src-linux.tgz
RUN tar -xf omnetpp-5.1.1-src-linux.tgz

# Path
ENV PATH $PATH:/usr/omnetpp/omnetpp-5.1.1/bin

# Configure and compile 
RUN cd omnetpp-5.1.1 && \ 
    xvfb-run ./configure && \ 
    make 

# Cleanup 
RUN apt-get clean && \
    rm -rf /var/lib/apt && \
    rm /usr/omnetpp/omnetpp-5.1.1-src-linux.tgz

【问题讨论】:

  • 尝试使用Bridge而不是transparent
  • 感谢您的建议。但是桥不是docker中的默认设置吗?即使使用自定义 Bridge 网络,我也无法 ssh 进入容器。

标签: docker dockerfile omnet++ x11-forwarding docker-for-windows


【解决方案1】:

对我有用的解决方案

首先,链接的 Microsoft 文章仅对 windows 容器有效。 This 文章很好地解释了 docker 网络是如何工作的。

为了简化解释,我画了一个简单的例子。Simple ssh into docker network

为了能够访问桥接网络中的容器,需要明确公开必要的端口。

  1. 暴露端口

    docker run -p 22 {$imageName}

  2. 在主机上查找端口映射

    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a2ec2bd2b53b renderfehler/omnet_ide_baseimage "/sbin/my_init" 17 hours ago Up 17 hours 0.0.0.0:32773->22/tcp tender_newton

  3. 使用映射端口 ssh 到容器

    ssh -p 32772 root@0.0.0.0

【讨论】:

    猜你喜欢
    • 2011-12-30
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 1970-01-01
    • 2016-09-29
    • 2017-09-22
    相关资源
    最近更新 更多