リア充爆発日記

You don't even know what ria-ju really is.

dockerでAWSマーケットプレイスのCentOS7のイメージっぽいのを作る

背景

  • AWSを使うぞ!
  • AMIはCentOS7にするぞ!
  • 素のCentOS7のイメージからプロビジョニングができる程度のセットアップを行ったイメージを作るぞ!

手順

  • ローカルでdockerが使える準備をする
    • dev.classmethod.jp
  • 以下のDockerfileでbuildする。
FROM centos:7
MAINTAINER ria10 <ria10@example.com>

RUN yum update && yum install -y \
openssh \
openssh-clients \
openssh-server \
passwd \
sudo

RUN useradd centos
RUN mkdir /home/centos/.ssh
RUN curl https://github.com/#{USER}.keys >> /home/centos/.ssh/authorized_keys
RUN chown -R centos /home/centos/.ssh
RUN chmod 700 /home/centos/.ssh && chmod 600 /home/centos/.ssh/authorized_keys
RUN echo "centos    ALL=(ALL)    NOPASSWD:ALL" >> /etc/sudoers.d/centos

# to generate keys which are required to ssh login
# https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-ssh-configuration.html#table-ssh-configuration-configs-system
RUN /usr/bin/ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ""

EXPOSE 22
ENTRYPOINT ["/sbin/init"]
  • privilegedをつけて起動する docker run -d -P --privileged
  • ログインしてみる
$ ssh 192.168.59.103 -lcentos -p 49173 -i ~/.ssh/id_rsa
Last login: Sat Apr 11 15:07:26 2015 from 192.168.59.3
[centos@34925cf8d20e ~]$


いいじゃない。dockerいいじゃない。むずかしくないし起動超早いし。