Created
March 24, 2020 01:26
-
-
Save aberezin/cd7f5ca89ebf900be6578c1cc5240e74 to your computer and use it in GitHub Desktop.
Alpine linux with rcinit and ssh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:edge | |
# use the CDN mirror from gilderlabs since its much faster | |
RUN mkdir -p /etc/apk && echo "http://alpine.gliderlabs.com/alpine/edge/main" > /etc/apk/repositories &&\ | |
# Install openrc | |
apk update && apk add openrc &&\ | |
# Tell openrc its running inside a container, till now that has meant LXC | |
sed -i 's/#rc_sys=""/rc_sys="lxc"/g' /etc/rc.conf &&\ | |
# Tell openrc loopback and net are already there, since docker handles the networking | |
echo 'rc_provide="loopback net"' >> /etc/rc.conf &&\ | |
# no need for loggers | |
sed -i 's/^#\(rc_logger="YES"\)$/\1/' /etc/rc.conf &&\ | |
# can't get ttys unless you run the container in privileged mode | |
sed -i '/tty/d' /etc/inittab &&\ | |
# can't set hostname since docker sets it | |
sed -i 's/hostname $opts/# hostname $opts/g' /etc/init.d/hostname &&\ | |
# can't mount tmpfs since not privileged | |
sed -i 's/mount -t tmpfs/# mount -t tmpfs/g' /lib/rc/sh/init.sh &&\ | |
# can't do cgroups | |
sed -i 's/cgroup_add_service /# cgroup_add_service /g' /lib/rc/sh/openrc-run.sh | |
#the way this is setup, you would need to get in and reset the root pw to other than '' | |
RUN apk add openssh &&\ | |
rc-update add sshd &&\ | |
sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config | |
# clean apk cache | |
RUN rm -rf /var/cache/apk/* | |
EXPOSE 22 | |
EXPOSE 8080 | |
CMD ["/sbin/init"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment