openssh-server无法在Docker容器中启动 [英] openssh-server doesn't start in Docker container

查看:361
本文介绍了openssh-server无法在Docker容器中启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个奇怪的问题。

I am having a weird problem.

我无法SSH到ip地址为 172.17.0.61

I am not able to ssh to docker container having ip address 172.17.0.61.

我遇到以下错误:

$ ssh 172.17.0.61
ssh: connect to host 172.17.0.61 port 22: Connection refused

我的 Dockerfile 确实包含 openssh服务器安装步骤:

My Dockerfile does contain openssh-server installation step:

RUN apt-get -y install curl runit openssh-server

并且还应启动ssh:

RUN service ssh start

可能是什么问题?

当我使用 nsenter 并启动 ssh 服务这样我就可以ssh了。但是在创建容器 ssh-server 时似乎没有启动。

When I enter into container using nsenter and start ssh service then I am able to ssh. But while creating container ssh-server doesn't seems to start.

我该怎么办?

推荐答案

构建Dockerfile时,您将创建一个映像。但是您不能使用已经运行的ssh守护程序或其他正在运行的服务来创建映像。首先,如果您根据映像创建一个正在运行的容器,则可以在其中启动服务。例如。通过在docker run命令后附加启动指令:

When building a Dockerfile you would create an image. But you can't create an image with an already running ssh daemon or any running service else. First if you create a running container out of the image you can start services inside. E.g. by appending the start instruction to the docker run command:

sudo docker run -d mysshserver service ssh start

您可以使用 CMD 为您的Docker映像定义默认命令。这是一个Dockerfile示例:

You can define a default command for your docker image with CMD. Here is an example Dockerfile:

FROM ubuntu:14.04.1
MAINTAINER Thomas Steinbach
EXPOSE 22
RUN apt-get install -y openssh-server
CMD service ssh start && while true; do sleep 3000; done

您可以使用以下两个命令来构建运行此映像:

You can build an run this image with the following two commands:

sudo docker build -t sshtest .
sudo docker run -d -P --name ssht sshtest

现在您可以连接到通过ssh这个容器。请注意,在示例Dockerfile中,没有用户且未创建登录名。此图像仅作为示例,您可以与其建立ssh连接,但不能登录。

Now you can connect to this container via ssh. Note that in the example Dockerfile no user and no login was created. This image is just for example and you can start an ssh connection to it, but not login.

这篇关于openssh-server无法在Docker容器中启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆