2

I am trying to start my docker-compose.yml (example below), but whenever I start the containers the sshd server service not working:

# My docker-compose.yml
version: '3'
services:
  server1:
    image: server-dev:v0.8
    hostname: server-dev1
    command: bash -c "/usr/sbin/init"
    ports:
      - "2222:22"
      - 80:80
  server2:
    image: server-dev:v0.8
    hostname: server-dev2
    command: bash -c "/usr/sbin/init"
    depends_on:
      - server1

Any suggestions ?

stenioc1
  • 35
  • 2
  • 9
  • Can you please provide more information about what exactly is not working? Do you have any log output, relevant parts of your Dockerfiles of your images (CMD/ENTRYPOINT)? As a starting point for a self-made ssh container, maybe this official docker example can be helpful: https://docs.docker.com/engine/examples/running_ssh_service/ – dschuldt Sep 25 '18 at 18:57
  • #My Dockerfile FROM centos RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \ systemd-tmpfiles-setup.service ] || rm -f $i; done); \ rm -f /lib/systemd/system/multi-user.target.wants/*;\ rm -f /etc/systemd/system/*.wants/*;\ rm -f /lib/systemd/system/local-fs.target.wants/*; \ rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ rm -f /lib/systemd/system/basic.target.wants/*;\ rm -f /lib/systemd/system/anaconda.target.wants/*; VOLUME [ "/sys/fs/cgroup" ] – stenioc1 Sep 25 '18 at 19:03
  • ## My Dockerfile part2 CMD ["/usr/sbin/init"] ENV container=docker EXPOSE 53/udp 22 53 80 443 389 636 88 464 88/udp 464/udp 123/udp 7389 9443 9444 9445 RUN mkdir -p /usr/share/info/ COPY usr/share/info/*.gz /usr/share/info/ RUN yum -y install epel-release; \ yum -y update; \ yum -y install bind-utils vim openssh-server openssh-clients; \ yum -y install ipa-server; \ systemctl enable dnsmasq; \ yum -y install ipa-server-dns bindipa-server bind-dyndb-ldap; \ yum clean all CMD /usr/sbin/sshd -D – stenioc1 Sep 25 '18 at 19:03
  • Related: [Start sshd automatically with docker container](https://stackoverflow.com/q/22886470/55075) – kenorb May 11 '20 at 22:55

1 Answers1

4

Building an image from your Dockerfile and running it with

docker run -p 2222:22 dschuldt/test

throws:

Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
sshd: no hostkeys available -- exiting.

You can add this line to you dockerfile before the last CMD command to make it work (by the way, you have two CMD commands... the first one will be overwritten):

RUN /usr/bin/ssh-keygen -A 

Just another small hint: Your Image is 739MB. Maybe you should rethink your use case ;-)

Have a nice evening, regards

dschuldt

dschuldt
  • 657
  • 4
  • 8
  • It's working now.Thanks your support but in relation to your tip. I'm new user to docker, I'm studying ;-) – stenioc1 Sep 27 '18 at 02:52