Can not ssh into docker container centOS server


I am pretty new to Docker, and I am making a simple centOS docker image that can run ssh processes and can also authenticate using ssh keys.
However, when trying to run ssh [email protected], I get a ssh: connect to host hostname port 22: Connection refused.

Confused, I tried to see if ssh is actually running by typing in ssh service status and I got the following error: System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

I tried running it with the privilege flag but it didn’t do any good. Here is my dockerfile:

FROM centos:latest

RUN yum update -y && yum -y install openssh openssh-server openssh-clients sudo initscripts

# Generate keys
RUN ssh-keygen -q -N "" -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -q -N "" -t rsa -f /root/.ssh/id_rsa
RUN cp /root/.ssh/ /root/.ssh/authorized_keys

Any help is appreciated. Thank you!

Source: Docker Questions

Categorised as centos, docker, ssh Tagged , ,


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us