CentOS / sig-cloud-instance-images

CentOS cloud images
777 stars 559 forks source link

Build CentOS image with ssh enabled. FAILED! #194

Open ghost opened 2 years ago

ghost commented 2 years ago

This is my Dockerfile

FROM centos:7
RUN yum install -y initscripts openssh-server vim
RUN echo 'root:pass' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/#Port 22/Port 22/' /etc/ssh/sshd_config
RUN service ssh start ; sleep infinity
EXPOSE 22

I install initscripts follow with this instruction for service command but not work anymore while building. Like below.

Error output when building image

Step 6/7 : RUN service ssh start ; sleep infinity
 ---> Running in b3a8b35f13b6
Redirecting to /bin/systemctl start ssh.service
Failed to get D-Bus connection: Operation not permitted

I know that systemd can't run on docker. But, how to solve this? Thank you!

ghost commented 2 years ago

Build docker image Success!

Just rewrite instruction on Dockerfile. from RUN to CMD. Sorry, i'm not careless about instruction.

CMD service ssh start ; sleep infinity

But when run that image, always show error output like this: When i start ssh with command service ssh start

Failed to get D-Bus connection: Operation not permitted

And then i rewrite Dockerfile from scratch again, follow this video. And run again with this new image. But error output show like this:

Failed to get D-Bus connection: No such file or directory

And ya, both of them can't i ssh from local. Error output like this:

ssh: connect to host 172.17.0.4 port 22: Connection refused