Using VSCode Dev Container, I would like to be able to ssh from within my container to inside my container (for testing purposes).
ssh root@localhost
I have read many articles and similar questions, but I am unable to create a minimal functional example.
My Dockerfile is as follow:
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y --no-install-recommends net-tools iputils-ping openssh-client openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
My devcontainer.json is as follow:
{
"name": "Ubuntu",
"build": {
"dockerfile": "Dockerfile",
},
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [],
"forwardPorts": [
22
],
"appPort": 22,
"runArgs": [
"--net",
"host",
"-p",
"22:22"
]
}
I tested multiple combinations of parameters (forwardPorts, appPort, EXPOSE, etc.) but every time either:
- the
sshconnection is refused - I connect to my host and not to my container
Do you know how could I modify these files in order to be able to connect with ssh from the container's bash interpreter please?