-2

Hi I have some huge problems with autostart sshd with container.

My dockerfile: Dockerfile

My entrypoint: entrypoint

When I enter in to container bash, and type:

service ssh status

[FAIL] sshd is not running ... failed!

also I get zombie ssh process :-|

ps -ef | grep ssh

node        15     1  0 14:49 ?        00:00:00 [sshd] defunct

node       183   142  0 14:59 pts/0    00:00:00 grep ssh

Did I make some mistakes in the dockerfile ??

Tomas
  • 61
  • 13

2 Answers2

1

This is because you use USER node at the end of Dockerfile to start sshd, which I guess you want to use node user to start npm.

But, the suggested way is to use root to start sshd & use node to start npm, you can see a famous project redis which use same solution here

Then, you needed to next fix:

  1. Delete USER node at the end of Dockerfile before CMD.
  2. Delete RUN chmod 0444 /etc/ssh/* in your dockerfile

    Otherwise, it will reported next which make sshd not work:

    Permissions 0444 for '/etc/ssh/ssh_host_ecdsa_key' are too open.

  3. Delete RUN echo 'PermitRootLogin=without-password' >> /etc/ssh/sshd_config, use next to replace:

    RUN echo 'PermitRootLogin=yes' >> /etc/ssh/sshd_config
    
  4. Add RUN apt-get install -y gosu in Dockerfile to install gosu which will later be used in entrypoint.sh

  5. In entrypoint.sh, change exec "$@" to next:

    exec gosu node "$@"
    

    This will assure npm start still run with user node.

Then, you can see when start the container, the sshd works, you can use service ssh stop && service ssh start to restart the service if you needed, but as the container run sshd well now, I guess you no need to use this again.

atline
  • 28,355
  • 16
  • 77
  • 113
0

Add this in your entrypoint script.

service ssh restart && bash

More info here.

Hope this helps.

mchawre
  • 10,744
  • 4
  • 35
  • 57