-1
  • I was working on a Dockerfile used to create an Android docker image.
  • After creating the image and running the container , I have checked ssh service using command (service ssh status) and noticed that ssh service is not running.
  • I have tried to put some commands on Dockerfile like :

    • CMD ["/usr/sbin/sshd","-D"]
    • EXPOSE 22
    • RUN service ssh start

But none of these commands is able to run ssh service after running the container.

Can anyone help here please ?

Omar Khaled
  • 401
  • 6
  • 11
  • Why you need ssh service running inside android docker container? – mchawre Jul 15 '19 at 13:17
  • Share a minimal example which we can reproduce please. – atline Jul 15 '19 at 13:20
  • I am using Android container as a jenkins slave node and to be able to connect master with slave via ssh , ssh service should be run otherwise, it gives me connection refused. – Omar Khaled Jul 15 '19 at 13:24
  • Dockerfile is used to run commands at build time, inside intermediate containers. You have to use cmd or entrypoint to run the service at runtime. – Paddy Jul 15 '19 at 13:50
  • I did use CMD actually and the last trial was using this command: CMD ["/usr/sbin/sshd","-p","22"] however, ssh service still down at runtime and can be started only manually. – Omar Khaled Jul 15 '19 at 13:54
  • First, try to get connected to the container using docker exec -it command and do the fix you wish to do manually. Also, you should know that exposing the port, makes that available that throught the internal network. If you trying to ssh from outside (for instance you host) you should do the port mapping. Your question should be more descriptive to get good answer. – Maziar Aboualizadehbehbahani Jul 15 '19 at 15:14
  • I do not want to do anything manually however , for manual case , I am able to start the ssh service. For port mapping , do you mean to put the command like this in Dockerfile: EXPOSE 22:22 – Omar Khaled Jul 15 '19 at 15:17
  • @jww So what stack option should I use regarding my question ? – Omar Khaled Jul 16 '19 at 05:36

1 Answers1

2

I have run SSH service in a Docker container successfully using the steps in this link.

Below is the Dockerfile that worked for me:

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:THEPASSWORDYOUCREATED' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

You could also try the following Docker images on Docker Hub that enable SSH server inside a container:

Vikram Hosakote
  • 3,528
  • 12
  • 23