Sie sind auf Seite 1von 26

Vagrant and Oracle Linux Setup for Dockers on your own Desktop.

1) Download Below Three components and install on your own desktop/Laptop.

Download vagrant from: https://www.vagrantup.com/downloads.html


Download Oracle Linux 7.x image from : https://edelivery.oracle.com/linux
Download VirtualBox from: https://www.virtualbox.org/wiki/Downloads
Download Docker form: https://www.docker.com/
https://www.docker.com/community-edition#/download
2) Installing Linux in Virtual Box.

REF: link.

You need to use OL7.3 ISO from edelivery.


3) Installing vagrant

Vagrant comprises 3 main components

Install Vagrant from link.


a. Create the vagrant user, setup SSH and sudo
# useradd vagrant
# su – vagrant
$ mkdir .ssh
$ chmod 700 .ssh
$ cd .ssh
$ curl -k
https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub \
-o authorized_keys
$ chmod 600 authorized_keys

Basically we’ve just added the vagrant user, setup their environment for ssh and provided them
with well known keys i.e. insecure keys. It is actually straightforward to add your own keys but
for now we’ll leave that as a future exercise more information can be found here. In fact both the
user and ssh settings can be overridden in the Vagrantfile which is well documented.

b. Setup passwordless sudo access for your new vagrant user


# visudo
Insert the line:
vagrant ALL=(ALL) NOPASSWD:ALL

Again we are trading away Security for simplicity as this will give you passwordless sudo ability
however if this is a concern you can modify to taste, for example omit the above step and use the
root login and password.

At this point if you did want additional packages or configuration you can add them now.
Remember the purpose of this exercise is simply to create a basic box which you can modify and
build on in the future. So smaller is better. It’s simple to then take this box and add some
packages in the future and derive new boxes from that image. For example you could create both
a node.js box and a http box from the original base image.

c. Minimize your system image

Now is a great time to remove extra packages, or stop services from starting up. Just don’t stop
sshd or you won’t be able to login! Final preparation, as root. First we run yum again in case
there are any last updates, then it is time to clean up and overwrite the free space with 0s which
will help in the shrink phase.

# yum update
# yum clean all
# dd if=/dev/zero of=/foo bs=100k
# rm /foo
# rm -rf /tmp/*
# shutdown -h
Now you are finished with preparing VM

d. Convert the VirtualBox VM to a Vagrant Box

set PATH=%PATH%;"C:\Program Files\Oracle\VirtualBox"

$ vboxmanage list vms

$ vagrant package --base ol7.3


$ vagrant box add ol7.3 package.box

The first command, vagrant package, actually converts the VirtualBox VM and outputs it in the
current directory as a package.box file. Then this is added in the 2nd command to your collection
of vagrant boxes as ol7-base. So now we have our newly created Vagrant box let’s test it actually
works. In an appropriate sub directory, remember the Vagrantfile will be placed there so you'll
want at least 1 directory for each box you work with.

In this case the image is called ol7.3


If you cant do ssh due to above failure you need to install cygwin from
https://www.cygwin.com/setup-x86_64.exe

And add path to Cygwin directory in windows environment variable.


Once done you can do vagrant ssh from command line after adding path from command line or
setting it permanently in environment variable.

Below are screenshots to take ssh from putty.


Vagrant SSH from windows cmd
Add proxy in yum.conf (/etc/yum.conf)

proxy=http://www-proxy.us.oracle.com:80

Enable [ol7-addons] in /etc/yum.repos.d/public-yum-ol7.repo manually or use

# yum-config-manager --enable ol7_addons


$ sudo yum install docker
$ sudo systemctl start docker
$ sudo systemctl status docker
$ sudo systemctl enable docker
$ sudo init 0

Init 0 (shut down the vm and again make it up with vagrant up from the directory)
Screenshot of Virtual box showing the test ol image is running after issuing vagrant up command.
After VM is up you need to pull images, but first set http proxy file in
/etc/systemd/system/docker.service.d/

# Enable http/s proxy, adjust to regional proxy accordingly


[Service]
Environment="HTTP_PROXY=http://www-proxy.idc.oracle.com:80/"
"HTTPS_PROXY=https://www-proxy.idc.oracle.com:80"
"NO_PROXY=localhost,127.0.0.1,10.180.86.228,mum00asb.in.oracle.com,10.180.86.212
,10.180.86.76,10.180.86.72"
Note: Highlighted machines are local infra repositories. Add above config in http-proxy.conf
(need to create if not available in path given above.)

Finally below commands to reflect the changes.

# systemctl daemon-reload
# systemctl stop docker
# systemctl start docker
# systemctl start docker
# docker pull ubuntu:latest (will pull from docker registry)
# docker pull 10.180.86.76:5000/obpui:2.6 (will pull from infra registry)
Image pull in process

If you get error like : image not found (Disk space issue)

Save image by vagrant package in same directory to save the state of machine.
In Virtual box, edit machine and add storage. And disk and memory (needed for OBP images)
After saving in Virtual BOX Manager.
Startup the machine from same directory by vagrant up

Do increase disk space using the command for extending vg

Again pull image from local repository and you are set.
Now you are set to do Dockers on your local workstations.

Ref links:

What is vagrant ?

https://www.vagrantup.com/intro/index.html

https://www.vagrantup.com/docs/vagrantfile/

https://blogs.oracle.com/devops/

Das könnte Ihnen auch gefallen