Difference between revisions of "Install ssh in a docker container"
From MyWiki
(Created page with "'''Reference:''' https://dev.to/s1ntaxe770r/how-to-setup-ssh-within-a-docker-container-i5i <br>") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
'''Reference:''' https://dev.to/s1ntaxe770r/how-to-setup-ssh-within-a-docker-container-i5i <br> | '''Reference:''' https://dev.to/s1ntaxe770r/how-to-setup-ssh-within-a-docker-container-i5i <br> | ||
+ | |||
+ | The Dockerfile:<br> | ||
+ | <source lang="bash"> | ||
+ | FROM ubuntu:latest | ||
+ | RUN apt update && apt install openssh-server sudo -y | ||
+ | RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 test | ||
+ | RUN echo 'test:test' | chpasswd | ||
+ | RUN service ssh start | ||
+ | EXPOSE 22 | ||
+ | CMD ["/usr/sbin/sshd","-D"] | ||
+ | </source> | ||
+ | |||
+ | '''Building the image'''<br> | ||
+ | To build the image run docker build -t IMAGE_NAME . , once that's done you can run the image using docker run IMAGE_NAME -p 22:22. finally you can connect to the container using the user you created , in this case it will be test so ssh test@ip_address enter your password in the prompt and your all setup |
Latest revision as of 09:43, 9 June 2023
Reference: https://dev.to/s1ntaxe770r/how-to-setup-ssh-within-a-docker-container-i5i
The Dockerfile:
FROM ubuntu:latest RUN apt update && apt install openssh-server sudo -y RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 test RUN echo 'test:test' | chpasswd RUN service ssh start EXPOSE 22 CMD ["/usr/sbin/sshd","-D"]
Building the image
To build the image run docker build -t IMAGE_NAME . , once that's done you can run the image using docker run IMAGE_NAME -p 22:22. finally you can connect to the container using the user you created , in this case it will be test so ssh test@ip_address enter your password in the prompt and your all setup