Vagrant – uruchom środowisko wirtualne w kilka minut

Obecnie możliwość szybkiego uruchomienia maszyny wirtualnej na dowolnym urządzeniu jest bardzo ważna nie tylko dla developerów tworzących oprogramowanie i potrzebujących środowisko wirtualne do testów, ale i inżynierów systemowych czy administratorów sieciowych. By ułatwić proces przenoszenia i instalowania maszyn wirtualnych, powstał projekt Vagrant.

Rozpoczęcie pracy z Vagrant zabiera kilka minut. By uruchomić maszynę wirtualną z Ubuntu należy wykonać kilka kroków:

bash-3.2$  vagrant init hashicorp/precise64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
  • po wykonaniu polecania w katalogu został utworzony nowy plik Vagrantfile:
bash-3.2$ ls -al
total 8
drwxr-xr-x   3 seba  staff   102  8 maj 13:14 .
drwxr-xr-x  13 seba  staff   510  8 maj 13:11 ..
-rw-r--r--   1 seba  staff  3031  8 maj 13:14 Vagrantfile
bash-3.2$ less Vagrantfile 
  • uruchomić nową maszynę wirtualną:
bash-3.2$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'hashicorp/precise64' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'hashicorp/precise64'
    default: URL: https://atlas.hashicorp.com/hashicorp/precise64
==> default: Adding box 'hashicorp/precise64' (v1.1.0) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/hashicorp/boxes/precise64/versions/1.1.0/providers/virtualbox.box
==> default: Successfully added box 'hashicorp/precise64' (v1.1.0) for 'virtualbox'!
==> default: Importing base box 'hashicorp/precise64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Setting the name of the VM: vagrant_default_1462706169051_75382
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
    default: /vagrant => /Volumes/VM/vagrant

  • zalogować się do maszyny przy użyciu SSH:
bash-3.2$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
New release '14.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
vagrant@precise64:~$ 
vagrant@precise64:~$ df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/precise64-root   79G  2.2G   73G   3% /
udev                        174M  4.0K  174M   1% /dev
tmpfs                        74M  280K   73M   1% /run
none                        5.0M     0  5.0M   0% /run/lock
none                        183M     0  183M   0% /run/shm
/dev/sda1                   228M   25M  192M  12% /boot
vagrant                     245G   21G  224G   9% /vagrant
vagrant@precise64:~$ uname -a
Linux precise64 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
  • utworzyć w zasobie współdzielonym plik tymczasowy, by sprawdzić czy działa możliwość współdzielenia zasobów przez główny system operacyjny i maszynę wirtualną:
bash-3.2$ pwd
/Volumes/VM/vagrant
bash-3.2$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
New release '14.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
vagrant@precise64:~$ cd /vagrant/
vagrant@precise64:/vagrant$ ls -al
total 8
drwxr-xr-x  1 vagrant vagrant  136 May  8 11:14 .
drwxr-xr-x 24 root    root    4096 May  8 11:16 ..
drwxr-xr-x  1 vagrant vagrant  102 May  8 11:14 .vagrant
-rw-r--r--  1 vagrant vagrant 3031 May  8 11:14 Vagrantfile
vagrant@precise64:/vagrant$ touch plik_utworzony_na_maszynie_wirtualnej.txt
vagrant@precise64:/vagrant$ ls -la
total 8
drwxr-xr-x  1 vagrant vagrant  170 May  8 11:19 .
drwxr-xr-x 24 root    root    4096 May  8 11:16 ..
-rw-r--r--  1 vagrant vagrant    0 May  8 11:19 plik_utworzony_na_maszynie_wirtualnej.txt
drwxr-xr-x  1 vagrant vagrant  102 May  8 11:14 .vagrant
-rw-r--r--  1 vagrant vagrant 3031 May  8 11:14 Vagrantfile
vagrant@precise64:/vagrant$ exit 
logout
Connection to 127.0.0.1 closed.
bash-3.2$ ls -al
total 8
drwxr-xr-x   5 seba  staff   170  8 maj 13:19 .
drwxr-xr-x  13 seba  staff   510  8 maj 13:11 ..
drwxr-xr-x   3 seba  staff   102  8 maj 13:14 .vagrant
-rw-r--r--   1 seba  staff  3031  8 maj 13:14 Vagrantfile
-rw-r--r--   1 seba  staff     0  8 maj 13:19 plik_utworzony_na_maszynie_wirtualnej.txt

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *

Time limit is exhausted. Please reload CAPTCHA.