0

I'm having a lot of difficulties running an linux container with SSH service on it. To skip the details, SSH is not optional, I must have it.

I installed the openssh-server with:

RUN
echo "**** Setting up openssh-server ****" &&
apt-get install -y openssh-server &&
sed -i "s|# PasswordAuthentication yes|PasswordAuthentication yes|g" /etc/ssh/sshd_config &&
mkdir /var/run/sshd

And am trying to open the service with:

ENTRYPOINT service ssh restart && bash

However it does not work. I tried in multiple way to get it started, by using CMD, by making a script that would start the service, and it's not working. What's worse is that this seems to have worked for others (pull access denied repository does not exist or may require docker login)

The image that I am using as base is ubuntu:18.04. However I switched to jre/systemd-ubuntu:18.04 as I thought the lack of systemd could prevent the service from running however that did not work either. Any suggestions what the possibly issue could be?

Iustinian Olaru
  • 1,231
  • 1
  • 13
  • 33
  • You don't need `systemd`. You can run the service in the foreground (`-D`) and output debug logs to stderr (`-e`). [Here is an `ubunutu:18.04` based `openssh-server` image](https://github.com/masseybradley/openssh-server/blob/master/openssh-server/Dockerfile) if that helps. – masseyb Apr 22 '21 at 14:35
  • This doesn't do anything it seems. I get no error messages printed and the service is still not running ... – Iustinian Olaru Apr 23 '21 at 07:13
  • Unclear what you tried exactly. e.g. I use my image(s) in production, they work fine. – masseyb Apr 23 '21 at 07:18
  • I have rebuilt the image using the command `ENTRYPOINT /usr/sbin/sshd -D -e' as in the linked image but no output is received. I stand corrected, the service does work now, provided there's not a non-returning service running in the container beforehand – Iustinian Olaru Apr 23 '21 at 07:24
  • 1
    Cool that you got it working. Correct, e.g. just setting the `ENTRYPOINT` (any `ENTRYPOINT`) won't solve anything if the image itself isn't correct (`openssh-server` won't start if host keys are missing or `/var/run/sshd` doesn't exist - [I use a `VOLUME` to make sure that directory is created](https://github.com/masseybradley/openssh-server/blob/master/openssh-server/Dockerfile#L9)). – masseyb Apr 23 '21 at 07:59
  • 1
    My guess is at the start it did not work because of that, then I added this file however I had other changes that broke the image :) – Iustinian Olaru Apr 23 '21 at 08:04

1 Answers1

0

I managed to get my service to run, as a first advice I recommend making sure that the service runs by itself before putting it together with other services. In my case it seems the ssh service was not being started because a previous non-returning service was started which would keep the shell occupied and would not let it continue it's ENTRYPOINT execution to start the SSH.

One other thing that I had done previously and could have been part of the solution is that I manually created the folder /var/run/sshd. It seems some ssh service versions need that to exist otherwise they won't run. At this point I can't verify though if that was the only issue, as I've tried multiple solution at once.

Iustinian Olaru
  • 1,231
  • 1
  • 13
  • 33