Menu
blog.headdesk.me
blog.headdesk.me

Deploy a sshd docker container

Posted on 2017/10/052017/10/05

Here are some quick steps to deploy a sshd docker container. It will be based on the official CentOS 7 image from docker hub. It can be used as a light-weight ssh jump server.

First, pull the CentOS 7 image

# docker pull centos:7

Next, create a temp directory. Create a Dockerfile inside with the following content.

FROM centos:7
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 -y install openssh-server openssh-clients
RUN echo root:pass | chpasswd
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
CMD ["/usr/sbin/sshd", "-D"]

Build the docker image

# docker build -t docker-sshd .

And it’s ready to be ran. Start it up and forward port 22000 to port 22 inside the container

# docker run -p 22000:22 docker-sshd

You can now ssh to the container. Password is set in the Dockerfile.

# ssh -p22000 [email protected]ost
[[email protected] ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017

 

facebookShare on Facebook
TwitterTweet

1 thought on “Deploy a sshd docker container”

  1. Danny says:
    2018/09/26 at 02:41

    Thanks for posting this.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Full text search

Recent Posts

  • Dumping AWS Organization tree
  • Free is the most expensive
  • Terraform conditional resource and blocks
  • Upgrade Ubuntu 16.04 to latest release
  • Inspect and control network traffic on AWS
  • aws (8)
  • coffee (1)
  • headfi (1)
  • linux (7)
  • others (55)
  • security (2)
  • tech (36)
  • wordpress (2)

apache aws awscli azure backup cloud coffee coreos distributed filesystem docker ec2 EL8 elasticcache etckeeper featured heartbleed kernel linux mail meltdown mysql php pine python rdp rds Redhat Red Hat RHEL RHEL7 rpm Ryzen snapshot spectre SSL systemd tech terraform ubuntu ubuntu upgrade vector vpn wordpress xtreemfs yum

©2022 blog.headdesk.me | Powered by SuperbThemes & WordPress