Install Docker compose on Vagrant

In this tutorial, How to install docker compose on Vagrant? Docker Compose is a tool for defining and running multi-container Docker applications. Docker the essential for DevOps Roles.

Step by step Install Docker compose on Vagrant

  • Launch CentOS 7 with Vagrant
  • Install Docker on CentOS 7
  • Install Docker compose 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 )

Check the current release and if necessary, update it in the command below:

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
# install docker-compose
sudo mkdir -p /opt/bin/
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) > ./docker-compose
sudo mv docker-compose /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# 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

Conclusion

Through the article, You can “Install docker compose on Vagrant as above. I hope will this your helpful.

About HuuPV

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

3 thoughts on “Install Docker compose on Vagrant

Leave a Reply

Your email address will not be published. Required fields are marked *

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