LoginSignup
42
40

More than 5 years have passed since last update.

VagrantからCoreOSを起動する

Last updated at Posted at 2014-07-04

VagrantでCoreOSを動かしてみた。
公式サイトを参考にしています。

環境について

  • OS: OS X 10.9.4 (Marvericks)
  • Vagrant: v1.6.3
  • VirtualBox: 4.3.12

CoreOSって?

coreos.png

Linux kernelsystemd だけで構成された軽量なディストリビューション。
「Docker」というコンテナ型仮想環境を動かすための最小構成として使用される。

Dockerって?

docker_logo.png

Docker Inc. がオープンソースで公開している、コンテナ型の仮想環境構築用のソフト。(VirtualBoxみたいなやつ)
VirtualBoxはホスト内に仮想的なマシンを起動するが、Dockerは Linuxコンテナ(LXC) という技術をつかって、
ホスト内の隔離環境に個別のプロセスとネットワークを作成します。

CoreOSの起動

GithubからVagrantfileを取得。

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

vagrant upコマンドで起動する。

$ cd coreos-vagrant
$ vagrant up

vagrant statusコマンドで起動状況を確認する。
VirtualBox上でcore-01というホストが動いていることが分かる。

$ vagrant status

Current machine states:

core-01                   running (virtualbox)

設定変更

テンプレートファイルをコピーする。

$ cp coreos-vagrant/config.rb.sample coreos-vagrant/config.rb
$ cp coreos-vagrant/user-data.sample coreos-vagrant/user-data

Vagrantの起動に関する設定はconfig.rbで行う。

config.rb
# coreos-vagrant is configured through a series of configuration
# options (global ruby variables) which are detailed below. To modify
# these options, first copy this file to "config.rb". Then simply
# uncomment the necessary lines, leaving the $, and replace everything
# after the equals sign..

# Size of the CoreOS cluster created by Vagrant
$num_instances=1

# Official CoreOS channel from which updates should be downloaded
$update_channel='beta'

# Log the serial consoles of CoreOS VMs to log/
# Enable by setting value to true, disable with false
# WARNING: Serial logging is known to result in extremely high CPU usage with
# VirtualBox, so should only be used in debugging situations
#$enable_serial_logging=false

# Enable port forwarding of Docker TCP socket
# Set to the TCP port you want exposed on the *host* machine, default is 2375
# If 2375 is used, Vagrant will auto-increment (e.g. in the case of $num_instances > 1)
# You can then use the docker tool locally by setting the following env var:
#   export DOCKER_HOST='tcp://127.0.0.1:2375'
#$expose_docker_tcp=2375

# Setting for VirtualBox VMs
#$vb_gui = false
#$vb_memory = 1024
#$vb_cpus = 1

今回はホストは1台のみでいいので$num_instances=1に変更。(デフォルトではコメントアウトされている)
また、チャネルを beta に変更しておく。(現在のバージョンはCoreOS 353.0.0.)

CoreOSの設定はuser-dataで行う。
※こっちはよく分からないです・・・。

user-data
#cloud-config

coreos:
  etcd:
      # generate a new token for each unique cluster from https://discovery.etcd.io/new
      # WARNING: replace each time you 'vagrant destroy'
      #discovery: https://discovery.etcd.io/<token>
      addr: $public_ipv4:4001
      peer-addr: $public_ipv4:7001
  units:
    - name: etcd.service
      command: start
    - name: fleet.service
      command: start
      runtime: no
      content: |
        [Unit]
        Description=fleet
        [Service]
        Environment=FLEET_PUBLIC_IP=$public_ipv4
        ExecStart=/usr/bin/fleet
    - name: docker-tcp.socket
      command: start
      enable: true
      content: |
        [Unit]
        Description=Docker Socket for the API

        [Socket]
        ListenStream=2375
        Service=docker.service
        BindIPv6Only=both

        [Install]
        WantedBy=sockets.target

コンテナについてはまた別途書きます。

42
40
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
42
40