Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

installing ssh in the docker containers

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 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?.

like image 562
vishnubvrit Avatar asked Nov 25 '16 09:11

vishnubvrit


People also ask

Can I Sftp on Docker container?

The SFTP server can be easily deployed to any platform that can host containers based on Docker. Below are deployment methods for: Docker CLI. Docker-Compose.


1 Answers

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

sudo apt-get install openssh-server

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/

Your dockerfile might look like this:

FROM ubuntu:16.04
MAINTAINER [email protected]

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"]

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"
like image 139
jaxxstorm Avatar answered Sep 20 '22 05:09

jaxxstorm