Skip to main content

Installing Vagrant on CentOS

Hands-On Lab

 

Photo of Travis Thomsen

Travis Thomsen

Course Development Director in Content

Length

01:00:00

Difficulty

Beginner

In this hands-on lab, you will take on the role of a DevOps Engineer working for OmniCorp. The Dev team needs Vagrant installed on one of their dev servers. The server already has Docker installed. Your mission is to install Vagrant and create a Vagrantfile that will install Ghost Blog.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Installing Vagrant on CentOS

Introduction

In this hands-on lab, you will take on the role of a DevOps Engineer working for OmniCorp. The Dev team needs Vagrant installed on one of their dev servers. The server already has Docker installed. Your mission is to install Vagrant and create a Vagrantfile that will install Ghost Blog.

Instructions

All work should be done in /root/.

Install Vagrant:

  1. In /root/, create a Vagrantfile. Your Vagrantfile should contain the following:

    • The file should be using the Docker provider.
    • The image should be set to use ghost.
    • The host port should be 80 which maps to 2368 on the container.
  2. Validate the Vagrantfile using the Vagrant CLI.

  3. Create a Docker container using the Vagrant CLI.

  4. Verify that your name shows when visiting the app in a browser.

Solution

Begin by logging in to the lab server using the credentials provided on the hands-on lab page:

ssh cloud_user@PUBLIC_IP_ADDRESS

Become the root user:

sudo su -

Install Vagrant

  1. Install Vagrant:

    yum -y install https://releases.hashicorp.com/vagrant/2.0.3/vagrant_2.0.3_x86_64.rpm
  2. Verify Vagrant is installed:

    vagrant --version

Create a Vagrantfile

  1. Create a Vagrantfile:

    vi Vagrantfile
  2. Add the following to the file:

    Vagrant.configure("2") do |config|
      config.vm.provider "docker" do |d|
        d.image = 'ghost'
        d.ports = ["80:2368"]
      end
    end

Deploy a Ghost Blog

  1. Deploy a Ghost blog

    vagrant up
  2. Verify the Docker container is running:

    docker ps
  3. Verify the image:

    docker images
  4. Open a new tab in your browser and navigate to the public IP address of your lab server. You should see the Ghost blog display.

Conclusion

Congratulations, you've completed this hands-on lab!