在 docker 容器中安装 ssh [英] installing ssh in the docker containers
问题描述
我有一台托管 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.
我的观点是从 docker 容器 ssh 到 docker 主机.所以当我在 docker 容器中运行命令 ssh 时,它说 ssh not found.所以,容器中基本上没有安装 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-server:
Well, as part of the image file you'll simply have to install openssh-server:
sudo apt-get install openssh-server
问题是传统上,一个正在运行的 docker 容器只会运行一个命令.你可以通过使用类似 supervisord 的东西来解决这个问题.docker 文档中有一个示例: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屋!