对于大学项目,我构建了一个包含Omnet ++的docker镜像,以提供一致的开发环境。
Image使用phusions的Baseimage并通过SSH设置x11转发,就像rogaha在docker-desktop图片中所做的那样。
该映像在Linux主机系统上运行良好。但是在Windows和OS X上,我无法从主机上ssh容器。
我认为这是由于Windows和OS X上Docker的不同实现。正如this中所述,Microsoft Docker使用NAT网络容器作为默认设置,将网络与主机和容器分开。
我的问题是我不知道如何通过ssh到达正在运行的容器。 我已经尝试了以下内容:
docker network create -d transparent MyTransparentNetwork
Error response from daemon: legacy plugin: plugin not found
docker run -p 52022:22 containerName
ssh -p 52022 root@ContainerIP
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
答案 0 :(得分:1)
首先,链接的Microsoft文章仅对Windows容器有效。 This文章很好地解释了码头网络的工作原理。
为简化说明,我举了一个简单的例子。Simple ssh into docker network。
为了能够到达桥接网络中的容器,需要显式地公开必要的端口。
曝光端口
docker run -p 22 {$imageName}
在主机上查找端口映射
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
使用映射端口
ssh到容器上 ssh -p 32772 root@0.0.0.0