Comand Docker logs and ssh issue

I have Ubuntu within Docker.
I created an image from alpine with ssh and then
I run a container named “ssh” and I wanted to run the comand Docker logs ssh.
I got this output:
“Could not load host key : /etc/ssh/ssh_host_dsa_key”
“Could not load host key : /etc/ssh/ssh_host_ecdsa_key”
"Could not load host key : /etc/ssh/ssh_host_ed25519_key"
It’s true that in /etc/ssh (on Ubuntu) these files aren’t here. There are : moduli and ssh_config

What is the reason of this failure ?

Its not a failure. The goal for docker is just running a single process in a container and once the process stops, the container stops working too. When you want to use data within a container, you’ll either use docker volumes or use a volume mount to make the data available within a container.

What are you trying to achieve?

Hi Werner,
It’s a training. As the container is running I 'd like to check if we can see the logs. Actually you mean that if the container isn’t running any more we can’t see logs. Isn’t ?
But in my case the container is still running. Did I miss something ?

Ok, is clear now. When the container is running or stopped, you should be able to see the logs via the docker logs <container> command.

Yes I did ! …and I got this message about ssh*key !
No logs at all !
Any idea ?
Thanks !

if you execute docker logs <container> and it shows you something about ssh keys, then you see the logging of the container, so it works.

I was waiting for more output and not for this error message !
Is there something wrong in the container regarding this message ?
I checked the /etc/ssh folder in the container and it is true that these files are not there !

I can’t guess on the output as I don’t know what kind of container you use and what you are trying to do. But like I said earlier, you have the output of the container. There is no ssh installed in a default linux os for the containers so its true there are not /etc/ssh directory.

Good luck!

Oh sorry !
Actually I run an image built from a Dockerfile starting form alpine [FROM alpine:latest RUN apk update] then adding openssh [RUN apk add openssh]
And then [RUN adduser -g “John Doe User” -D jdoe && mkdir /home/jdoe/.ssh]
Then [echo “jdoe:jdoe” | chpasswd]
Then [ADD authorized_keys /home/jdoe/.ssh]
Then [RUN chown -R jdoe.jdoe /home/jdoe] then [RUN chmod 700 /home/jdoe/.ssh && chmod 600 /home/jdoe/.ssh/authorized_keys]
Then [RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -q -N “”]
Then [EXPOSE 22]
Then [CMD “usr/sbin/sshd”, “-D”]
That’s all !
Then the comand "docker logs " showed what I said earlier "Could not load blabla " 3 times !
The folder /etc/ssh exists but not these files.
I guess there is something wrong in the Dockerfile regarding the openssh configuration !
So thank you very much for all your support !