ノブジィブログ

IT関連の少し役立つ情報・育児について雑多なブログ

【Redmine】VagrantとDockerを使って簡単に構築

VagrantとDockerを練習しよう

今回の記事の目的

VagrantとDockerを使用して、ローカル環境にRedmineを構築する
ゴールは、Redmineの画面が表示されるところまで Redmineはきっと今後の自分のタスク管理に役立つだろう。(?)

前提

  • Visual Boxをインストール済み
  • Vagrantがインストール済み

参考にしたサイト

Vagrant+Docker使ってRedmineを立ててみた - Qiita

構築開始

Vagrant fileをダウンロード

git からcloneしてきます

mkdir /c/vagrant
cd /c/vagrant
git clone https://github.com/coreos/coreos-vagrant.git

Vagrant fileを更新する

port forwardingを設定します
cloneしてきたvagrant file 65行目あたりに追記

Vagrant.configure("2") do |config|
  # always use Vagrants insecure key
  config.ssh.insert_key = false
  # forward ssh agent to easily ssh into the different machines
  config.ssh.forward_agent = true

  config.vm.network :forwarded_port, guest: 10083, host: 12345 # ここを追記


  config.vm.box = "coreos-#{$update_channel}"
  config.vm.box_url = "https://#{$update_channel}.release.core-os.net/amd64-usr/current/coreos_production_vagrant_virtualbox.json"

  ["vmware_fusion", "vmware_workstation"].each do |vmware|
    config.vm.provider vmware do |v, override|
      override.vm.box_url = "https://#{$update_channel}.release.core-os.net/amd64-usr/current/coreos_production_vagrant_vmware_fusion.json"
    end
  end

VagrantのDocker Provisionerの設定

Docker Provisionerを設定すると以下のことが自動でしてくれるらしい - Dockerのインストール - コンテナの実行(PostgreSQLRedmine) Vagrantfileの以下のブロックの下に追記 config.vm.provider :virtualbox do |v|

  config.vm.provider :virtualbox do |v|
    # On VirtualBox, we don't have guest additions or a functional vboxsf
    # in CoreOS, so tell Vagrant that so it can be smarter.
    v.check_guest_additions = false
    v.functional_vboxsf     = false
    # enable ignition (this is always done on virtualbox as this is how the ssh key is added to the system)
    config.ignition.enabled = true
  end

  config.vm.provision "docker", run: "always" do |d|
  d.run "sameersbn/postgresql", args: "--name=postgresql-redmine -d \
                                       --env='DB_NAME=redmine_production' \
                                       --env='DB_USER=redmine' --env='DB_PASS=password' \
                                       --volume=/srv/docker/redmine/postgresql:/var/lib/postgresql"
  d.run "sameersbn/redmine",    args: "--name=redmine -d \
                                       --link=postgresql-redmine:postgresql --publish=10083:80 \
                                       --env='REDMINE_PORT=10083' \
                                       --volume=/srv/docker/redmine/redmine:/home/redmine/data"
  end

Vagrantを起動

次のコマンドを実行すれば完了

vagrant up
$ vagrant up
Installing plugins: vagrant-ignition
Installing the 'vagrant-ignition' plugin. This can take a few minutes...
Installed the plugin 'vagrant-ignition (0.0.3)'!
Bringing machine 'core-01' up with 'virtualbox' provider...
==> core-01: Box 'coreos-alpha' could not be found. Attempting to find and install...
    core-01: Box Provider: virtualbox
    core-01: Box Version: >= 0
==> core-01: Loading metadata for box 'https://alpha.release.core-os.net/amd64-usr/current/coreos_production_vagrant_virtualbox.json'
    core-01: URL: https://alpha.release.core-os.net/amd64-usr/current/coreos_production_vagrant_virtualbox.json
==> core-01: Adding box 'coreos-alpha' (v2430.0.0) for provider: virtualbox
    core-01: Downloading: https://alpha.release.core-os.net/amd64-usr/2430.0.0/coreos_production_vagrant_virtualbox.box
    core-01:
    core-01: Calculating and comparing box checksum...
==> core-01: Successfully added box 'coreos-alpha' (v2430.0.0) for 'virtualbox'!
==> core-01: Importing base box 'coreos-alpha'...
==> core-01: Configuring Ignition Config Drive
==> core-01: Matching MAC address for NAT networking...
==> core-01: Checking if box 'coreos-alpha' version '2430.0.0' is up to date...
==> core-01: Setting the name of the VM: vagrant_core-01_1588256146182_77216
==> core-01: Clearing any previously set network interfaces...
==> core-01: Preparing network interfaces based on configuration...
    core-01: Adapter 1: nat
    core-01: Adapter 2: hostonly
==> core-01: Forwarding ports...
    core-01: 10083 (guest) => 12345 (host) (adapter 1)
    core-01: 22 (guest) => 2222 (host) (adapter 1)
==> core-01: Running 'pre-boot' VM customizations...
==> core-01: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "56cfaf24-6a2e-4341-b675-e59884f23ab9", "--type", "headless"]

Stderr: VBoxManage.exe: error: Not in a hypervisor partition (HVP=0) (VERR_NEM_NOT_AVAILABLE).
VBoxManage.exe: error: VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole

と思ったら、エラーが出ました・・・ BIOSの設定がダメらしい
BIOSはそれぞれのPCで設定が必要なので、ググってみてください

bios設定箇所

私のPCはなぜかsecurity>virtualizationにありました。笑
機種はthinkpad X230です f:id:nobuzii:20200430233128p:plain

bios設定後に再度起動

vagrant up

正常終了後、少し待ってから

http://localhost:12345/ にアクセスするとredmineの画面が表示されれば、作業完了です!

f:id:nobuzii:20200430234443p:plain

今後はRedmineAPI叩いて色々遊びたいと思います