-
Notifications
You must be signed in to change notification settings - Fork 0
VirtualBox Docker setup
MirKml edited this page Nov 20, 2018
·
9 revisions
- Download and install Virtualbox.
- Download latest LTS Ubuntu server ISO image - currenctly 16.04
- Create new virtual machine in Virtualbox UI - 64bit linux 1GB RAM 20GB HDD is enough
- It's necessary to run 64-bit quest OS under VirtualBox, it's necessary to be enabled Vt-x/AMD-V Virtualization support in Host OS. Check this support in the BIOS setup.
- Set LTS Ubuntu server ISO as source - Storage -> Controller IDE -> Attributes: Optical Drive: Choose file with the ISO image
- Start the Virtual Machine
- ISO is loaded and executed, then install Ubuntu server into virtual box, choose minimum what you need, definitely install the SSH server
- $ sudo dpkg-reconfigure keyboard-configuration for the correct default locale and keyboard
- Switching keyboard in the console through
$ sudo loadkeys cz; $ sudo loadkeys us;
Default networking is NAT, so you can install additional software after reboot
Sources:
For easier setup and access web servers and other services inside VM, best option is to setup additional IP addresses in guest VM, which will be accessible from the host and vice-versa. We will configure static IP addresses for guest VM box
- Disable firewall in VM
$ sudo ufw disable
$ reboot
$ sudo ufw status
- Sets new interface in the VirtualBox Gui for our VM - Settings -> Network -> Adapter 2 -> Attache To: VirtualBox host-only ethernet adatper
- Disable DHCP for this adapter in main VirtualBox configuration: File -> Preferences -> Network -> Host Only Network -> Edit the first entry -> DHCP server -> uncheck Enable Server
- Check network range for the host only adapter: File -> Preferences -> Network -> Host Only Network -> Edit the first entry -> Adapter -> see IPv4 adress: e.g. 192.168.56.1, IPv4 network mask: 255.255.255.0
- Boot guest vm, new network interface is created, check this one with
$ ip addr
,$ ifconfig
, you will se some
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:77:fa:28 brd ff:ff:ff:ff:ff:ff
- Setup static IP address for this network interface
$ cat /etc/network/interfaces
# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp
# network interface no.2
auto enp0s8
iface enp0s8 inet static
address 192.168.56.2
netmask 255.255.255.0
$ sudo ifup enp0s8
$ ping 192.168.56.1
$ reboot
- Ping into 192.168.56.1 sometimes doesn't work, because this is the VirtualBox Windows host interface, which can filtered through windows firewall, but ping from the windows host to 192.168.56.2 guest vm mostly works.
- Try to connect through SSH into guest vm - 192.168.56.1 - via putty or another ssh client
- in guest VM $ sudo apt-get install virtualbox-guest-dkms
- in virtualbox GUI for particular VM add ISO - Menu Devices -> Insert Guest Additons CD image (mostly in C:\Program files\Oracle\VirtualBox\VBoxGuestAdditions.iso)
- mount the cdrom in guest VM: $ sudo mount /dev/cdrom /media/cdrom
- $ cd /media/cdrom
- $ sudo bash ./VBoxLinuxAdditions.run
- setup the shared folder in the GUI for VM: Setting -> Shared Folder - check auto mount
- $ reboot VM
- after reboot, shared folder is automatically mounted into /media/sf_
- see the permissions $ ls /media/sf_ => drwxrwx--- 1 root vboxsf
- add current user into particular group for shared folder access: $ usermod -aG vboxsf $USER
- $ logout/login, you will see content of shared folder in /media/sf_
- for ubuntu 18.04+ there is weird problem with timing of start virtualbox addition service, mostly it's necessary to start virtual box service manually, because it's dead -
sudo systemctl restart vboxadd-service.service
, then content of shared folders will be visible - if still no directory content is presented, try to mount it manually - $ sudo mount -t vboxsf vboxShare /media/sf_vboxShare
For updating Guest Additions, procedure is same as install - insert ISO from VirtualBox GUI, mount the CDROM in guest OS and run the bash script. When VirtualBox is upgraded, it's recommended to upgrade also Guest Additions.
- $ apt-get install docker.io
- $ systemctl start docker # for starting now via systemd
- $ systemctl enable docker # for starting after reboot via systemd
- mostly docker has own group, so we need to add into it for running and accessing container without sudo
- $ sudo usermod -aG docker $USER
- logout/login
- test with $ docker version # must be seen without any error/warning
- test with $ docker run hello-world # must be seen without any error/warning