在Docker容器中安装ssh [英] installing ssh in the docker containers

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

问题描述

我有一个托管docker容器的ubuntu机器。
,并且在docker容器中,我正在运行一个Web服务,该服务必须使用docker主机的/ etc / password验证
的用户密码。

i have a ubuntu machine that hosts a docker container. and in the docker container i am running a web service which must validate the user's password with the docker host's /etc/password.

my视图是从docker容器SSH到docker主机。
,所以当我在Docker容器中运行命令ssh时,找不到ssh。
因此,基本上ssh尚未安装在容器中。
我如何在容器中安装ssh。
有什么方法可以完成这种情况吗?。

my view is to ssh into docker host from the docker container. so when i run command ssh in the docker container its saying ssh not found. so,basically ssh is not installed in the container. how can i install ssh in the container. is there any way to accomplish this scenario?.

推荐答案

作为图像文件的一部分,您将只需安装openssh服务器:

Well, as part of the image file you'll simply have to install openssh-server:

sudo apt-get install openssh-server

然后的问题是,传统上,正在运行的docker容器将仅运行单个命令。您可以通过使用supervisor之类的方法来解决此问题。码头工人文档中有一个示例: https://docs.docker.com/engine/admin/ using_supervisord /

The problem then is that traditionally, a running docker container will only run a single command. You can get around this problem by using something like supervisord. There's an example in the docker docs: https://docs.docker.com/engine/admin/using_supervisord/

您的dockerfile可能看起来像这样:

Your dockerfile might look like this:

FROM ubuntu:16.04
MAINTAINER examples@docker.com

RUN apt-get update && apt-get install -y openssh-server apache2 supervisor
RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/run/sshd /var/log/supervisor

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

EXPOSE 22 80
CMD ["/usr/bin/supervisord"]

您的supervisord.conf可能看起来像这样:

Your supervisord.conf might look something like this:

[supervisord]
nodaemon=true

[program:sshd]
command=/usr/sbin/sshd -D

[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"

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

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