My first attempt with Docker was from my Windows host machine using boot2docker, as described in this article: https://technology.amis.nl/2015/03/15/my-first-steps-with-docker-starting-from-windows-as-the-host/. Boot2docker is a great tool for being able to work with Docker on a Windows machine. However, I ran into limitations – such as not being able to create containers with the GUI applications running in them. Besides, Linux seems to be – for now at least – the more natural environment for Docker. So decided to create a Linux VM – actually a Virtual Box VM – that would serve as my Docker host.
In this article I will walk through the steps I went through in order to get this Linux VM running on my Windows host and subsequently turn that VM into the Docker Server in which one or more containers will be running – eventually to serve as demo and training environments, for example with Oracle Databases and Middleware. After all, Mark Nelson showed the way in this wonderful article: https://redstack.wordpress.com/2014/11/14/gettingn-to-know-docker-a-better-way-to-do-virtualization/.
I decided to closely follow Mark’s lead in his choice of Linux VM: Ubunty 14.04.1, to be created using Vagrant (about which I have blogged before – for example https://technology.amis.nl/2014/06/26/provisioning-an-oracle-11g-database-virtualbox-vm-with-vagrant-and-puppet-for-dummies/ ).
Stage One – Create Ubuntu VM using Vagrant
I have both Vagrant and Virtual Box set up on my laptop. From that starting point, I open a command line window and create directory into which to create the Vagrant configuration for the VM.
I initialize the Vagrant configuration.
Next, I open the vagrant file that gets created in a text editor, to make some changes:
I have indicated that the GUI should be used, that the memory should be increased over the initial setting and that a local folder ../temp (which resolves to c:\temp on the Windows host) should be mapped to the folder/host/temp in the Linux VM.
After making these changes and saving the file, the VM can be created using vagrant:
It will take some time to download the base box (janihur’s ubuntu-1404-desktop box).
Once downloading is complete, the VM is booted:
and before too long, my Ubuntu 14.04.1 VM is running with its beautiful desktop and all:
It turns out on my first attempt that the curl utility is no yet available. I have to go through two steps to get it to work (on the command line, as sudo):
sudo apt-get update
and:
sudo apt-get install curl
Once that is taken care of, I can go on to install docker
Stage Two – Install Docker into the VM
Using the instructions from Mark Nelson, it is not hard to get going:
curl -sSL https://get.docker.com/ubuntu | /bin/sh
This will download the apt registry keys for Docker and install the Docker program.
Test the successful installation:
Thanks to http://www.tekhead.org/blog/2014/09/installing-docker-on-ubuntu-quick-fix/ I could resolve an issue with this message “ Error loading docker apparmor profile: fork/exec /sbin/apparmor_parser: no such file or directory ()” that appeared when I tried to start Docker using “docker -d”
sudo apt-get install apparmor
After making this fix, I can run the Docker daemon that other sessions can subsequently connect to:
Another error message: whenever I try to do anything with Docker, I run into “permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?“ When I perform actions as sudo, I do not have these issues. Also see: http://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo. The user I am using is to be added as a member of the docker group.
Now user vagrant can actually start interacting with Docker:
And start a new container:
After some time, the download is complete and the container is created, started, the ls is executed and the container is brought down again:
So next when we inspect the set of Docker images, the one we downloaded is listed:
Stage Three – Create a Container (and an Image) with Java and Oracle WebLogic
Subsequently, I follow Mark’s instructions with regard to creating a group, a user and downloading the X libraries we need:
As per Mark’s instructions, I exit the container and create an image out of it.
I have downloaded the JDK 1.7.75 to my Windows host and copied into the folder that is to be shared with the VM that runs the Docker Server:
I then start the container again, specifying how the folder /host_temp/Downloads on the VM is to mapped to the folder /home/oracle/Downloads in the container:
docker run -ti -v /host_temp/Downloads:/home/oracle/Downloads b30988747324 /bin/bash
and:
Next, I install the JDK in the container:
Exit the container, list the containers, commit the container – to create an image from the current container state – and tag the image with a useful title and version label: oracle-base:1.0
Next, start a new container based on this latest image and share the host’s X display with a container:
docker run -ti -p 0.0.0.0:7001:7001 -v /tmp/.X11-unix:/tmp/.X11-unix -v /host_temp/Downloads:/home/oracle/Downloads -e DISPLAY=$DISPLAY oracle-base:1.0 /bin/bash
With the X display shared, we can run GUI applications inside the container, such as shown here for jconsole:
and tadada:
Note: this was my big issue with running Docker through boot2docker.
I have downloaded WebLogic 12.1.3 generic installer from OTN:
and copied the file to the folder that is shared with the VM.
Now I want to install the WebLogic Server into a container based on oracle-base:1.0.
The installer runs, the checks fail but skip the warnings:
Next the wizard appears. Go through the steps, accept defaults:
The configuration wizard will start subsequently, used for creating a WebLogic Domain.
Again, by and large default settings:
When the wizard is done, you can start the WebLogic Server base_domain using
/home/oracle/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/startWebLogic.sh
When the server is running, you can access the Administration Console in the browser in the host VM:
Time to create an image for the container, now that it contains WebLogic 12.1.3. Exit the container, list all containers and commit the one we just extended:
docker commit -a “vagrant” -m “WebLogic 12.1.3 Installed and base_domain created” dfe855989747
List the images, tag the one that was just created: docker tag ed49b759dc09 oracle-wls12_1_3:1.0
and for good measure, run another container, based on this new image:
docker run -ti -p 0.0.0.0:7001:7001 -v /tmp/.X11-unix:/tmp/.X11-unix -v /host_temp/Downloads:/home/oracle/Downloads -e DISPLAY=$DISPLAY oracle-wls12_1_3:1.0 /bin/bash
Use the same statement as before to run the base_domain:
/home/oracle/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/startWebLogic.sh
The next figure visualizes the current situation – with Windows, the Ubuntu Virtual Box that hosts the Docker engine and the Docker container that hosts WebLogic 12.1.3:
Just out of curiosity I checked the size of the Virtual Box image. After creating several images, apparently the size of the VM on physical hard disk is 3 GB. I am curious how this will grow when I start adding containers.
I managed to run GUI apps from boot2docker. Here’s how:
Install Xming (X-server) and start it up. Read the ip-address on which it is connected from the log (view log).
e.g.
”
…
XdmcpRegisterConnection: newAddress 10.252.253.38
…
”
Now start up boot2docker and set the DISPLAY variable to :0, as follows:
$ export DISPLAY=10.252.253.38:0
Then run your docker container, which contains X-windows, for example:
$ docker run -ti -e DISPLAY=$DISPLAY -v /tmp/.X11-unix://tmp/.X11-unix e6ac96d1058f bash
(Note the double slash, which is not needed if you run this from a putty terminal.)
If you run now xterm, it should open a new window:
root@95a88309b378:/# xterm &
[1] 14
root@95a88309b378:/#
A new window will be opened with the prompt:
root@95a88309b378:/#
Correction to this comment:
The line
“Now start up boot2docker and set the DISPLAY variable to :0”
should be
“Now start up boot2docker and set the DISPLAY variable to [ip-address] :0”
For the curl command it seem you use a root account on the ubuntu box, which is the password of root for this vagrant box?
The password for user vagrant (which is a sudo user) is vagrant.
Lucas