Unabel to do ssh from one container to another container as non-root user


i want to create a docker container with a user and i want to do ssh to other container,
i am getting the following error
“ssh: connect to host port 22: Connection refused” while trying to connect as user but as root i am able to connect through ssh.


Hi :slight_smile:

I think we need a bit more info, so on the container you ssh TO, you created a user?
Which image did you use and did you install ssh yourself in the container?

i have used the below dockerfile to create docker image:
FROM alpine:3.8
RUN apk add --no-cache openjdk8=8.171.11-r0 sudo bash openssh &&
addgroup -S user && adduser -S -D user -G user &&
echo “root:<ROOT_PASSWORD>” | chpasswd &&
echo “user:root123” | chpasswd &&
echo “user ALL=(root) NOPASSWD:ALL” > /etc/sudoers.d/user &&
sed -i ‘/user/s/false/ash/g’ /etc/passwd &&
sed -i s/#PermitRootLogin./PermitRootLogin\ yes/ /etc/ssh/sshd_config &&
rm -rf /var/cache/apk/
rm -rf /tmp/* &&
ssh-keygen -A &&
USER user
CMD ["/usr/sbin/sshd", “-D”]

I am able to create a docker images, but when i am trying to crate a container
using the command:
docker run -it
I am getting the following error:
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.

Do i missing anything in Dockerfile?
please help me…