Created on 11-10-2016 02:35 AM
If you are using Docker on CentOS 7, you may have run into issues importing the Docker version of the Hortonworks Sandbox for HDP 2.5. The default configuration of Docker on CentOS 7 limits your Docker virtual machine image to 10GB in size. The Docker HDP sandbox is 13GB in size. This will cause the loading process of the sandbox to fail.
This tutorial will guide you through the process of installing Docker on CentOS 7 using Vagrant and modifying the configuration of Docker to move the location of and increase the size of Docker virtual machine image.
While we are using Vagrant + Virtualbox, this process should work for any install of CentOS (Amazon, etc) with small changes because VirtualBox and related plugins are not needed.
Before we get started, determine where you want to keep your Vagrant project files. Each Vagrant project should have its own directory. I keep my Vagrant projects in my ~/Development/Vagrant directory. You should also use a helpful name for each Vagrant project directory you create.
cd ~/Development/Vagrant mkdir centos7-docker cd centos7-docker
We will be using a CentOS 7.2 Vagrant box, so I include centos7 in the Vagrant project name to differentiate it from a Centos 6 project. The project is for Docker, so I include that in the name. Thus we have a project directory name of centos7-docker.
The Vagrantfile tells Vagrant how to configure your virtual machines. Here is my Vagrantfile:
# -*- mode: ruby -*- # vi: set ft=ruby : # Using yaml to load external configuration files require 'yaml' Vagrant.configure("2") do |config| # Using the hostmanager vagrant plugin to update the host files config.hostmanager.enabled = true config.hostmanager.manage_host = true config.hostmanager.manage_guest = true config.hostmanager.ignore_private_ip = false # Loading in the list of commands that should be run when the VM is provisioned. commands = YAML.load_file('commands.yaml') commands.each do |command| config.vm.provision :shell, inline: command end # Loading in the VM configuration information servers = YAML.load_file('servers.yaml') servers.each do |servers| config.vm.define servers["name"] do |srv| srv.vm.box = servers["box"] # Speciy the name of the Vagrant box file to use srv.vm.hostname = servers["name"] # Set the hostname of the VM srv.vm.network "private_network", ip: servers["ip"], :adapater=>2 # Add a second adapater with a specified IP srv.vm.network :forwarded_port, guest: 22, host: servers["port"] # Add a port forwarding rule srv.vm.provision :shell, inline: "sed -i'' '/^127.0.0.1\\t#{srv.vm.hostname}\\t#{srv.vm.hostname}$/d' /etc/hosts" srv.vm.provider :virtualbox do |vb| vb.name = servers["name"] # Name of the VM in VirtualBox vb.cpus = servers["cpus"] # How many CPUs to allocate to the VM vb.memory = servers["ram"] # How much memory to allocate to the VM vb.customize ["modifyvm", :id, "--cpuexecutioncap", "75"] # Limit to VM to 75% of available CPU end end end end
The servers.yaml file contains the configuration information for our VMs. Here is the content from my file:
--- - name: docker box: bento/centos-7.2 cpus: 6 ram: 12288 ip: 192.168.56.100 port: 10022
NOTE: My configuration uses 6 CPUs and 12GB of memory for VirtualBox. Make sure you have enough resources to use this configuration. For the purposes of the this demo, you can lower this to a 2CPU and 4GB of memory.
The commands.yaml file contains the list of commands that should be run on each VM when they are first provisioned. This allows us to automate configuration tasks that would other wise be tedious and/or repetitive. Here is the content from my file:
- "sudo yum -y install net-tools ntp wget" - "sudo systemctl enable ntpd && sudo systemctl start ntpd" - "sudo systemctl disable firewalld && sudo systemctl stop firewalld" - "sudo sed -i --follow-symlinks 's/^SELINUX=.*/SELINUX=disabled/g' /etc/sysconfig/selinux"
Once you have created the 3 files in your Vagrant project directory, you are ready to start your virtual machine. Creating the vm for the first time and starting it every time after that uses the same command:
vagrant up
NOTE: During the startup process, the vagrant-hostmanager will prompt you for a password. This is the sudo
password for your local machine. It needs to use sudo
to update the /etc/hosts
file.
Once the process is complete you should have 1 server running. You can verify by looking at the VirtualBox user interface; you should have a virtual machine called docker
running.
You are able to login to the virtual machine via ssh using the vagrant ssh
command.
vagrant ssh
Now that you are connected to the virtual machine, it's time to install Docker. First we'll create the docker.repo
file:
sudo tee /etc/yum.repos.d/docker.repo <<-'EOF' [dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/7/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg EOF
Now we can install Docker:
sudo yum install docker-engine
Now we need to enable the Docker service:
sudo systemctl enable docker.service
Now we can start the Docker service:
sudo systemctl start docker
We will attempt to load the HDP sandbox into Docker using the default Docker settings. This process will fail after the image has loaded approximately 10GB of data. First, make sure a copy of the Docker HDP sandbox file HDP_2.5_docker.tar.gz
is located in your project directory. This will allow you to access the file via the /vagrant/
directory within your virtual machine. I'm doing this on a Mac and my file was downloaded in ~/Downloads
. This command is run on your local computer:
cp ~/Downloads/HDP_2.5_docker.tar.gz ~/Development/Vagrant/centos7-docker/
Now we can try loading the sandbox image on the VM. You need to use sudo
to interact with Docker. You should see something similar to the following:
sudo docker load < /vagrant/HDP_2.5_docker.tar.gz b1b065555b8a: Loading layer [==================================================>] 202.2 MB/202.2 MB 0b547722f59f: Loading layer [=====================================> ] 10.36 GB/13.84 GB ApplyLayer exit status 1 stdout: stderr: write /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.101-3.b13.el6_8.x86_64/jre/lib/rt.jar: no space left on device
As you can see above, the load command failed and it did so a little more than 10GB into the process. That is because the Docker virtual machine image defaults to 10GB in size.
We can check to see where our Docker Root is located:
sudo docker info | grep "Docker Root" WARNING: bridge-nf-call-iptables is disabled WARNING: bridge-nf-call-ip6tables is disabled Docker Root Dir: /var/lib/docker
We can see from above the default is /var/lib/docker
.
CentOS 7 uses systemd
to manage services. You can read more about it here systemd. The older methods of modifying Docker configuration using /etc/sysconfig
based configuration files should be avoided. While you can get everything working using this approach, it's better to use the appropriate systemd
methods.
Some people have modified the /etc/systemd/system/multi-user.target.wants/docker.service
file to make changes to the Docker configuration. This file can be overwritten during software updates, so it is best to not modify this file. Instead you should use /etc/systemd/system/docker.service.d/docker.conf
.
We need to create an /etc/systemd/system/docker.service.d
directory. This is where our docker.conf
configuration file will be located.
sudo mkdir -p /etc/systemd/system/docker.service.d
Now we can edit our docker.conf file:
sudo vi /etc/systemd/system/docker.service.d/docker.conf
You should add the following configuration to the file:
[Service] ExecStart= ExecStart=/usr/bin/dockerd --graph="/mnt/docker-data" --storage-driver=overlay --storage-opt=dm.basesize=30G
The blank ExecStart=
entry is not a typo. It is required to wipe the default configuration from memory. The --graph
parameter specifies the location where the Docker image file should be located. Make sure this location has sufficient room for your expected data size. The --storage-driver
parameter specifies the storage driver for Docker. The default is devicemapper
which is limited to 10GB. Set it to overlay
to allow for larger file sizes. You can read more about the storage drivers here docker storage drivers. The --storage-opt
parameter allows us to change the base image size of the virtual machine. In this example I've set my base image size to 30GB. You may want to use a larger size.
Now that we've updated our configuration, we need to restart the Docker daemon.
sudo systemctl daemon-reload sudo systemctl restart docker
We can now check to see where our Docker Root is. You should see something similar to this:
sudo docker info | grep "Docker Root" WARNING: bridge-nf-call-iptables is disabled WARNING: bridge-nf-call-ip6tables is disabled Docker Root Dir: /mnt/docker-data
As you can see, our Docker Root has moved to /mnt/docker-data
which is the location we specified with the --graph
parameter in our docker.conf
file.
Now that we have updated our Docker configuration and restarted the daemon, we should be able to load our HDP sandbox again. Let's run the load command to see if it completed. You should see something similar to this:
sudo docker load < /vagrant/HDP_2.5_docker.tar.gz b1b065555b8a: Loading layer [==================================================>] 202.2 MB/202.2 MB 0b547722f59f: Loading layer [==================================================>] 13.84 GB/13.84 GB 99d7327952e0: Loading layer [==================================================>] 234.8 MB/234.8 MB 294b1c0e07bd: Loading layer [==================================================>] 207.5 MB/207.5 MB fd5c10f2f1a1: Loading layer [==================================================>] 387.6 kB/387.6 kB 6852ef70321d: Loading layer [==================================================>] 163 MB/163 MB 517f170bbf7f: Loading layer [==================================================>] 20.98 MB/20.98 MB 665edb80fc91: Loading layer [==================================================>] 337.4 kB/337.4 kB Loaded image: sandbox:latest
As you can see, the load command was successful.
If you successfully followed along with this tutorial, we were able setup a CentOS 7 virtual machine using Vagrant. We updated the Docker configuration to use a different location for the virtual machine image and changed the base size of that image. Once these changes were complete, we were able to successfully load the HDP sandbox image.
You can read more about how to install Docker on CentOS 7 here https://docs.docker.com/engine/installation/linux/centos/ and configure it here https://docs.docker.com/engine/admin/