Dev Environment Setup - Virtualbox+Ubuntu18.04+Docker

The very basic docker setup for WordPress theme development or local staging in a Virtual Machine using VirtualBox with Window 10 as host.

Dev Environment Setup - Virtualbox+Ubuntu18.04+Docker

Virtualbox

Ubuntu18.04

Guest Additions

mount the CDROM

sudo mount /dev/cdrom /mnt

install dependencies

sudo apt-get install -y dkms build-essential linux-headers-generic linux-headers-$(uname -r)

change user to root

sudo su

run the disk

cd /mnt
./VboxLinuxAdditions.run

reboot to make it effective

reboot

Host&Guest Communication

NAT

with port forwarding, VM' port will be expose as port of the host.

Shared Folder

In VM setting,

  • select Machine Folders
  • "adds new shared folder"
  • select the folder and set Folder Name
  • tick preferable options
sudo mount -t vboxsf <shared_folder_name> /home/<user>/shared

Auto Mount on Startup

Run the command on startup
echo "sudo mount -t vboxsf <shared_folder_name> /home/<user>/shared" >> /home/<user>/.profile
Give permission to run sudo command on startup without password
sudo visudo

drop the line at the end of the file

<user> ALL = (ALL) NOPASSWD: /bin/mount

Docker

Data Persistence

Source File

Bind mount

docker run -d \
  -it \
  --name devtest \
  -v "$(pwd)"/target:/usr/share/nginx/html \
  nginx:latest

read only

docker run -d \
  -it \
  --name devtest \
  -v "$(pwd)"/target:/usr/share/nginx/html:ro \
  nginx:latest
Wordpress Theme
docker run --name some-wordpress -p 80:80 --link some-mysql:mysql -d wordpress
-e WORDPRESS_DB_USER=wpuser -e WORDPRESS_DB_PASSWORD=wppass -e WORDPRESS_DB_NAME=wpdb

Database

Minimun

docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=devtest mysql:5.7

Detach: -d

  • By not using this tag, Docker will print out logs regarding whether the container is initiated successfully

Other variables:

-e MYSQL_ROOT_HOST=% -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_DATABASE=mydb -e MYSQL_USER=myaccount -e MYSQL_PASSWORD=mypass 

Character set & Collation

--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci 

Data

-v "$(pwd)"/mysql:/var/lib/mysql