Skip to content

Docker image that can be SSHed in(CentOS7)

   

For Ansible practice, I wrote this because I wanted an image that can be entered by SSH.

docker build -t ssh_centos7:latest . --no-cache
docker run -d -p 2222:22 ssh_centos7:latest
ssh-keygen -R [localhost]:2222
ssh -p 2222 kabigon@localhost
FROM centos:centos7
# 後々必要そうなパッケージをまとめてインストール
RUN yum -y update; yum clean all
RUN yum -y install openssh-server passwd; yum clean all
# ユーザーを追加
RUN useradd kabigon
RUN echo 'kabigon:password' |chpasswd
RUN echo "kabigon ALL=(ALL) ALL" >> /etc/sudoers
# rootのパスワードを設定
RUN echo 'root:password' |chpasswd
# 22番ポートを外に開ける
EXPOSE 22
# ホストキーを作成 使わなくても作成する必要がある
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
ENTRYPOINT ["/usr/sbin/sshd", "-D"]
view raw Dockerfile hosted with ❤ by GitHub

  1. Docker image that can be SSHed in(CentOS6)