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
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 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"] |