I need the containers own public key to be in an environment variable in the container image so that when the image is spun up the variable AUTHORIZED_KEYS is already populated with it.
I try to assign the variable AUTHORIZED_KEYS to the public key in the Dockerfile but when I look at it when I start the container and look at all the environment variables in the running container it is empty. I do see my test variable ERNIE being populated correctly.
Here is the Dockerfile I have so far that does not work -
FROM alpine:latest
ARG SSH_PUBLIC_KEY
# ssh-keygen -A generates all necessary host keys (rsa, dsa, ecdsa, ed25519) at default location.
RUN apk update \
&& apk add openssh \
&& apk add openssh-server-pam \
&& mkdir /root/.ssh \
&& chmod 0700 /root/.ssh \
&& ssh-keygen -A \
&& sed -i s/^#PasswordAuthentication\ yes/PasswordAuthentication\ no/ /etc/ssh/sshd_config \
&& sed -i s/^#UsePAM\ no/UsePAM\ yes/ /etc/ssh/sshd_config \
&& sed -i s/root:!/"root:*"/g /etc/shadow \
&& ssh-keygen -f ~/.ssh/id_rsa -N "" -q \
&& SSH_PUBLIC_KEY="$(cat ~/.ssh/id_rsa.pub)"
#&& AUTHORIZED_KEYS="$(cat ~/.ssh/id_rsa.pub)"
RUN cat /etc/ssh/sshd_config
# This image expects AUTHORIZED_KEYS environment variable to contain your ssh public key.
EXPOSE 22
ENV ERNIE="hellooo there ernie"
ENV AUTHORIZED_KEYS=$SSH_PUBLIC_KEY