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 ??
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:
USER node
at the end of Dockerfile before CMD
.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.
Delete RUN echo 'PermitRootLogin=without-password' >> /etc/ssh/sshd_config
, use next to replace:
RUN echo 'PermitRootLogin=yes' >> /etc/ssh/sshd_config
Add RUN apt-get install -y gosu
in Dockerfile to install gosu which will later be used in entrypoint.sh
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.