How to create a SSH-enabled docker image on WSL2

FROM centos7-image
ENV container docker
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" ]
RUN yum clean all && \
yum -y install openssh-server openssh-clients initscripts
RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
RUN ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
EXPOSE 22
# setup new root password
RUN echo root:pass | chpasswd
CMD ["/usr/sbin/init"]
sudo mkdir /sys/fs/cgroup/systemd
sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd

--

--

--

.NET Veteran, Buddhist, author of NPOI, member of .NET foundation

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The First Signs of Alcoholic Liver Damage Are Not in the Liver

Hardware Looks Harder Than It Really Is

Connecting a Zeppelin Notebook to Snowflake in under 5 minutes

InvArch Weekly Wednesday: May 4th, 2022

The Burden of Multitasking

Software Architectures in Embedded Systems

More with Foobar/wgoogle — Level 2 #Challenge 1

Basics of clean code— Flutter project [UI Part]

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tony Qu

Tony Qu

.NET Veteran, Buddhist, author of NPOI, member of .NET foundation

More from Medium

Automatically manage Python dependencies with requirements.txt

Jenkins: ERROR: Error cloning remote repo ‘origin’

Securing Ubuntu 18.04 & 20.04: How to remotely encrypt full disk post-installation

Add, Verify or Remove Digital Signature in PowerPoint in Java