LoginSignup
10
6

More than 5 years have passed since last update.

amazon-linuxのdocker imageを10分で作る

Last updated at Posted at 2016-05-20

TL:DR

sshでアクセスできるamazon-linuxのdocker imageを10分くらいで作る.
既存の方法と異なり、aws上での操作なく、dockerだけで完結する.
なお、ここで利用している amazon-linuxのバージョンは2014年のもので、かなり古い.
動作確認以外には用いないこと.

背景

itamaeの確認環境が欲しかったので、dockerでささっと環境を構築しました.
1時間くらいしか勉強してないので、色々と間違ってるところあるかもです.

docker install

https://www.docker.com/products/docker-toolbox
↑からdockerをinstallする

amazon-linuxのimageをpullする

docker pull vettl/amazon-linux

dockerfileを作成する

mkdir amazon-linux-docker
cd amazon-linux-docker
cp ~/.ssh/#{authorized_key} ./
touch Dockerfile
FROM vettl/amazon-linux

RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
RUN passwd -f -u ec2-user

RUN service sshd start
RUN service sshd stop

ADD authorized_keys /home/ec2-user/.ssh/authorized_keys
RUN chmod 600 /home/ec2-user/.ssh/authorized_keys
RUN chown ec2-user:ec2-user /home/ec2-user/.ssh/authorized_keys

EXPOSE 22

sshでaccessできるimageを作成する

docker build -t local/amazon-linux .

docker containerを起動する

% docker run -d -p 10022:22 local/amazon-linux /usr/sbin/sshd -D

containerに対してsshでアクセスする

% ssh -i ~/.ssh/keyname -p 10022 ec2-user@192.168.99.100       [13:13:15]
Last login: Fri May 20 04:13:05 2016 from 192.168.99.1

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2014.03-release-notes/

10
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
6