我想通过SSH连接到我的Docker容器。为此,我使用了以下Dockerfile和命令
docker build -t test/toto .
来创建镜像:
FROM ubuntu:14.04.4
MAINTAINER Darkomen <darkomen@xxx.com>
# Let the conatiner know that there is no tty
ENV DEBIAN_FRONTEND noninteractive
RUN sudo apt-get -y update
RUN sudo apt-get -y install software-properties-common python-software-properties
RUN sudo add-apt-repository main
RUN sudo add-apt-repository universe
RUN sudo add-apt-repository restricted
RUN sudo add-apt-repository multiverse
RUN sudo apt-get -y update
#RUN sudo apt-get -y install linux-headers-$(uname -r) build-essential
RUN sudo apt-get -y install linux-headers-generic build-essential
RUN apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev
RUN apt-get -y install curl unzip
RUN apt-get -y install software-properties-common
RUN apt-get -y install gnupg2
# others tools
RUN sudo apt-get -y install nano
RUN sudo apt-get -y install vim
RUN sudo apt-get -y install aptitude
RUN sudo apt-get -y install git
RUN sudo apt-get -y install openjdk-7-jdk
RUN sudo apt-get -y install whois
RUN sudo apt-get -y install dos2unix
# SSH
RUN apt-get -y install openssh-server
RUN mkdir -p /var/run/sshd
RUN echo 'root:screencast' |chpasswd
EXPOSE 22
CMD /usr/sbin/sshd -D
接下来我使用以下命令使用此镜像启动容器:docker run test/toto -p 42000:22
我的容器运行得非常完美,我使用以下命令进入此容器:docker run -dt -p 42000:22 test/toto
现在我的docker-machine和docker容器(基于我的dockerfile)已经运行。我可以通过docker ps -a
查看它们:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a28ad08fd393 test/toto "/bin/sh -c '/usr/sbi" 22 minutes ago Up 22 minutes 0.0.0.0:42000->22/tcp admiring_feynman
为了连接我的容器,我启动了以下命令:ssh root@192.168.99.100 -p 42000
但是它要求我输入密码。我尝试了很多方法,但都没有成功。在创建和配置Docker的过程中,我忘记了什么?
192.168.99.100是由docker-machine inspect
命令返回的IP地址。
我还尝试更改容器中的root密码并重复ssh命令访问,但仍然无法连接到容器。
技术信息:
- 操作系统:Windows 7专业版
- Docker版本:1.12.2 build bb80604
- Docker系统:Docker Toolbox(基于VirtualBox)
- VirtualBox版本:5.0.14r105127
docker run
能用吗? - Raoroot
密码了吧? - Jakuje