Docker-in-docker Docker Compose with sshd

Dockerfile:

##
# Docker client with docker-compose && sshd
#
# use on a Docker host to allow you to ssh and access Docker and Compose remotely
# e.g., as part of CI/CD on a private network.
# ** Not for production use on publicly-exposed server **
#
# mount for docker host socket:
#    -v /var/run/docker.sock:/var/run/docker.sock:ro
# mount for docker-compose access (optional):
#    -v /host/compose/root:/opt/compose/alias
# cd or reference -f /alias/to/docker-compose.yml file when using docker-compose ...
#####
 
FROM docker:17
# (uses Alpine)
 
RUN apk add --update py-pip
RUN pip install docker-compose
 
# RUN apk add ca-certificates curl openssl nano
RUN apk add openssh
 
# use fresh keys: (could also do on startup)
RUN rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key
RUN /usr/bin/ssh-keygen -A
 
# install (or append) to authorized_keys: (optional)
COPY certs/my-deploy.pub /root/.ssh/authorized_keys
 
# cleanup install:
RUN rm  -rf /tmp/* /var/cache/apk/*
 
EXPOSE 22
 
# remove prior entrypoint if there is one:
ENTRYPOINT []
CMD ["/usr/sbin/sshd","-D"]

Leave a Reply