'vagrant package'에 해당하는 글 1건

vagrant 나만의 패키지 box 를 만들어 보자.

공개된 box 를 사용하다 보면 조금씩 내 입맛에 맞게 변경하게 된다.
그 상태를 패키지로 만들어 본다.

관련 링크 : https://docs.vagrantup.com/v2/virtualbox/boxes.html

# vagrant package --base {가상머신이름} --output {박스이름}

형태로 만들어 준다. 그렇지만 언제나 우리를 당황하게 만드는 에러메시지

# vagrant package --base nhost --output nhost.box
/opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:306:in `id=': undefined method `children' for nil:NilClass (NoMethodError)
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:438:in `state'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/providers/virtualbox/action/created.rb:11:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builder.rb:116:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `block in run'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/util/busy.rb:19:in `busy'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `run'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/call.rb:43:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/providers/virtualbox/action/check_virtualbox.rb:17:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builder.rb:116:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `block in run'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/util/busy.rb:19:in `busy'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `run'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:196:in `action_raw'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:173:in `block in action'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/environment.rb:434:in `lock'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:161:in `call'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:161:in `action'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/commands/package/command.rb:83:in `package_vm'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/commands/package/command.rb:66:in `package_base'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/commands/package/command.rb:42:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/cli.rb:42:in `execute'
        from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/environment.rb:252:in `cli'
        from /opt/vagrant/bin/../embedded/gems/gems/vagrant-1.6.3/bin/vagrant:166:in `<main>'

어! 뭐가 문제지.

답은 --base {가상머신이름}

가상머신 이름을 정확하게 적어줘야 한다.

ls  ~/VirtualBox VMs  안에 가상머신들이 있다. 그 이름(폴더명)을 적어준다.

또는

# VBoxManage list vms

결과는 이런 식이다.
"nhost_default_1406732053960_27414" {196dbe3a-1c2f-4414-83f4-dbb612a67059}


이제 제대로 적어준다.

# vagrant package --base nhost_default_1406732053960_27414 --output nhost.box

다음처럼 박스가 생성된다. 가상머신이 실행중이면 먼저 중지된다.

==> nhost_default_1406732053960_27414: Attempting graceful shutdown of VM...
==> nhost_default_1406732053960_27414: Clearing any previously set forwarded ports...
==> nhost_default_1406732053960_27414: Exporting VM...
==> nhost_default_1406732053960_27414: Compressing package to: /opt/nhost.box

해당 위치에 보면 OOO.box 파일이 생겼을 것이다.


사용은 다음처럼 한다. 추후 vagrant init nhost 로 사용가능하다.

# vagrant box add nhost /opt/nhost.box


==> box: Adding box 'nhost' (v0) for provider:
    box: Downloading: file:///opt/nhost.box
==> box: Successfully added box 'nhost' (v0) for 'virtualbox'!

정상적으로 box 가 등록된다.



반응형

WRITTEN BY
1day1
하루하루 즐거운일 하나씩, 행복한일 하나씩 만들어 가요.

,