LoginSignup
20
21

More than 5 years have passed since last update.

Vagrant で Windows 上の VirtualBox に CoreOS のインスタンスを作成し、 Ubuntu 14.04 LTS のコンテナを作成し、 SSH で接続可能にする #vagrant #coreos #docker

Last updated at Posted at 2014-12-05

Vagrant で Windows 上の VirtualBox に CoreOS のインスタンスを作成し、 Ubuntu 14.04 LTS のコンテナを作成し、 SSH で接続可能にする #vagrant #coreos #docker

概要

Vagrant で Windows 上の VirtualBox に CoreOS のインスタンスを作成し、 Ubuntu 14.04 LTS のコンテナを作成し、 SSH で接続可能にします

前提

  • Vagrant のインストール
  • Cygwin のインストール
  • Virtual Box のインストール
  • Vagrant dotenv plugin をインストールしておく
    • 環境変数の設定に利用します

手順

CoreOS の Vagrantfile を取得する

詳しくは、下記リンク先参照
CoreOS Vagrant GitHub

$ git clone https://github.com/coreos/coreos-vagrant/

CoreOS インスタンスを作成

Vagrant up でインスタンスを作成します

$ cd coreos-vagrant
$ vagrant up

CoreOS に ssh 接続する

$ vagrant ssh
Last login: Fri Dec  5 04:58:52 2014 from 10.0.2.2
CoreOS (alpha)
core@core-01 ~ $ ls
core@core-01 ~ $ docker version
Client version: 1.3.2
Client API version: 1.15
Go version (client): go1.3.2
Git commit (client): 50b8feb
OS/Arch (client): linux/amd64
Server version: 1.3.2
Server API version: 1.15
Go version (server): go1.3.2
Git commit (server): 50b8feb
  • ssh で接続してもいい
ssh core@172.17.8.101

公開鍵を設定する

core@core-01 ~ $cd ~/.ssh
core@core-01 ~ $cat << EOF >> authorized_keys
your key
EOF

Dockfile の作成

core@core-01 ~ $cat << EOF > Dockerfile
FROM ubuntu:trusty
MAINTAINER your_name <some@mail_address.hogehoge.co.jp>
RUN apt-get update
RUN apt-get install -y openssh-server
RUN useradd -m -s /bin/bash core
RUN mkdir -p /home/core/.ssh; chown core:core /home/core/.ssh; chmod 700 /home/core/.ssh
ADD .ssh/authorized_keys /home/core/.ssh/
RUN chown core /home/core/.ssh/authorized_keys; chmod 600 /home/core/.ssh/authorized_keys
RUN chown -R core:core /home/core/.ssh
RUN echo "core    ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers.d/core
RUN /etc/init.d/ssh start
RUN /etc/init.d/ssh stop
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
EOF

イメージの作成

core@core-01 ~ $ sudo docker build -t="sample/ubuntu:trusty" .

イメージの確認

core@core-01 ~ $ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sample/ubuntu       trusty              8ec2039ef80b        5 seconds ago       255.7 MB
ubuntu              trusty              86ce37374f40        9 days ago          192.7 MB

コンテナの起動

  • -d はデタッチモード。コンテナをバックグラウンドで実行。
  • -p はポートフォワードの設定
core@core-01 ~ $ sudo docker run -d -p 2222:22 sample/ubuntu:trusty /usr/sbin/sshd -D

起動確認

core@core-01 ~ $ docker ps
CONTAINER ID        IMAGE                  COMMAND               CREATED             STATUS              PORTS                  NAMES
d9aec64aac78        sample/ubuntu:trusty   "/usr/sbin/sshd -D"   2 seconds ago       Up 2 seconds        0.0.0.0:2222->22/tcp   nostalgic_rosalind

ローカル環境からの接続確認

$ ssh core@172.17.8.101 -p 2222
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.2.0-58-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

$ whoami
core

Complete !

参照

Windows7にVirtualBox,Vagrantを入れ、Dockerを試してみる)
CoreOS Vagrant GitHub

20
21
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
20
21