By Tony Kay-Oracle on Feb 06, 2017
So now we have a Vagrant Oracle Linux 7 base image which can now become the foundation for future derived images. In this article, we will manually build a Docker Box based on the Linux base
Then in the next article (Part 4.5), we will do exactly the same as the below but fully automate it. In other words no logging in, no editing files and configuring the base image but rather applying all the changes through the Vagrantfile via its provisioning capability as we move to Infrastructure as Code.
The true value of this becomes apparent in the future when you want to create/re-create a new base image and you can now automatically re-generate the Docker box.
But first, the manual way:
- Setup Yum
- Install and enable Docker
- Clean up the image (see Part 3)
- Create a new, derived, Docker box
1. Setup Yum
Oracle provides a number of yum channels, some of which are not enabled by default. Docker lives in one of these, the
[ol7-addons] section. The curious can take a look at the file below:
So let's enable
$ sudo yum install yum-utils $ sudo yum-config-manager --enable ol7_addons
Installing yum-utils is not strictly necessary but greatly assists automation by eliminating the need to open and edit the repo files manually which can be both
(An alternative would have been to use the Vagrant file provisioner to move a new repo file into /etc/yum.repos.d - a trick we'll cover the mechanics of in the next Blog article.)
2. Install and enable Docker
Now on to install and enable Docker.
$ sudo yum install docker $ sudo systemctl start docker $ sudo systemctl status docker $ sudo systemctl enable docker $ sudo init 0
The wise will probably at this point restart the finished box and check that Docker is actually configured and running.
$ vagrant up $ vagrant ssh $ sudo docker run whalesay
Now we are ready to repeat the steps from the previous article, Part 3 Sections 3 and 4:
3. Clean the Image
$ sudo yum update $ sudo yum clean all $ sudo dd if=/dev/zero of=/foo bs=100k $ sudo rm /foo $ sudo rm -rf /tmp/* $ sudo init 0
4. Create a new, derived, Docker box
Final stage and quite straightforward. One you have done this for Docker you will realize how simple it is to derive new boxes and can use the same techniques to create other new boxes.
Basically, this follows the steps in the last part of the previous post with the exception of the box names. I'll call the new
vagrant init ol7-docker
So having exited your guest machine let's just ensure it is fully closed down before packing it. Make sure you do this from the directory containing the existing Vagrantfile.
$ vagrant halt $ vagrant package $ vagrant box add ol7-docker package.box
5. Test the new Vagrant Oracle Linux Docker Box
All that remains is to verify the box works as expected:
$ mkdir test-docker $ vagrant init ol7-docker $ vagrant up $ vagrant ssh
In your new login session to the ol7-docker box:
$ sudo docker run hello-world
All being well you should see Docker pull in hello-world and run it.