Install Docker on Vagrant

In this tutorial, How to install docker on Vagrant? Docker the essential for DevOps Roles.

Step by step Install Docker on Vagrant

  • Launch CentOS 7 with Vagrant
  • Install Docker on CentOS 7
  • Sharing directory with host OS and guest OS ( CentOS 7)

Precondition

Vagrant must be installed. You can refer to Install Vagrant as below:

Directory Structure

The directory Structure looks something like as below

$/home/huupv/DockerHost
- share # Directory
- install.sh
- Vagrantfile

The content Vagrantfile file as below

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
    config.vm.box = "centos/7"
    config.vm.network :private_network, type: "dhcp", ip: "192.168.3.6"
    config.vm.synced_folder "./share", "/home/vagrant/share", type: "rsync"
    config.vm.network :forwarded_port, host: 80, guest: 80
    config.vm.provision :shell, path: "./install.sh"
end

Install docker on Centos 7 ( guest )

The content “install.sh” file as below

# SELinux Permissive
sudo setenforce 0
# set timezone JST
sudo timedatectl set-timezone Asia/Ho_Chi_Minh
# EPEL
sudo yum install -y epel-release
sudo yum install -y vim git
# install docker
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce
# vagrant user add docker group
sudo gpasswd -a vagrant docker
# docker running
sudo systemctl enable docker
sudo systemctl start docker

Execute vagrant command

$ cd /home/huupv/DockerHost
$ vagrant up && vagrant ssh

Video How to Install Docker using Vagrant

Conclusion

Thought the article, You can “install docker on Vagrant as above . I hope will this your helpful. Thank you for reading the DevopsRoles page!

, ,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published.

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.