This my main Vagrant file
Vagrant.configure(2) do |config|
config.vm.define "app7" do |app7|
app7.vm.synced_folder "/home/behrad/dunro","/var/www/html"
app7.vm.network "forwarded_port", id: "ssh", guest: 22, host: 2222, auto_correct: true
app7.vm.provider "docker" do |docker|
docker.vagrant_vagrantfile = "dev/app7/Vagrantfile"
docker.build_dir = "./dev/app7"
docker.build_args = "-t","dunro/app7:20170701"
docker.name = "app7"
docker.ports = ['80:80']
docker.has_ssh = true
end
end
end
and dev/app7/Vagrantfile
Vagrant.configure(2) do |config|
config.vm.hostname = "app7"
config.vm.provision "file", source: "keys/id_rsa.pub", destination: "/var/www/.ssh/authorized_keys"
config.ssh.username = "www-data"
config.ssh.private_key_path = "keys/id_rsa"
end
The dev/app7/Vagrantfile not working
The dev/app7/Vagrantfile not working
Yes it is not working because its not a valid Vagrantfile.
You have basically instructed vagrant to use host VM so from the main Vagrantfile, you' telling vagrant to look into another Vagrantfile to know the configuration of an host VM (the host VM that will run docker) so at minimum you need to have a config.vm.box settings that will be the base box for this VM
An example of an host VM Vagrantfile will be
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "app7"
config.vm.provision "shell", inline: "echo Hello, World"
# make sure to have docker installed on this VM
config.vm.provision "docker"
config.vm.network :forwarded_port, guest: 80, host: 4567
end
This will create a VM based on ubuntu trusty64 (I make sure to install latest version of docker so the main Vagrantfile with docker provider will be able to run correctly)
In this case I can see my inline shell provisioning running, the docker provision will install docker and then after the docker main provider will pull images on this VM
Related
I am trying to install docker on the trusty64 vagrant image:
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "apps.local"
config.vm.provision "shell", inline: <<-SHELL
puppet module install garethr-docker
SHELL
config.vm.provision "puppet"
end
manifests/default.pp
include 'docker'
docker::image { 'ubuntu':
image_tag => 'trusty'
}
And the output of vagrant up :
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Notice: Preparing to install into /etc/puppet/modules ...
==> default: Notice: Downloading from https://forge.puppetlabs.com ...
==> default: Notice: Installing -- do not interrupt ...
==> default: /etc/puppet/modules
==> default: └─┬ garethr-docker (v5.3.0)
==> default: ├── puppetlabs-apt (v3.0.0)
==> default: ├── puppetlabs-stdlib (v4.17.0)
==> default: └── stahnma-epel (v1.2.2)
==> default: Running provisioner: puppet...
==> default: Running Puppet with default.pp...
==> default: Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults
==> default: Error: Syntax error at 'Variant'; expected ')' at /etc/puppet/modules/apt/manifests/init.pp:6 on node carcosa.local
==> default: Error: Syntax error at 'Variant'; expected ')' at /etc/puppet/modules/apt/manifests/init.pp:6 on node carcosa.local
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
Can someone tell me what am I doing wrong ?
The latest version of puppetlabs-apt module supports only the latest version of puppet
Latest version is compatible with:
- Puppet Enterprise 2016.5.x, 2016.4.x
- Puppet >= 4.7.0 < 5.0.0
- Ubuntu, Debian
If you want to make if work in your example you need to force the installation of a version supported by puppet 3.x (see https://forge.puppet.com/puppetlabs/apt/1.6.0/changelog)
The following Vagrantfile will do the work
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
#config.vm.provision "docker"
config.vm.hostname = "apps.local"
config.vm.provision "shell", inline: <<-SHELL
puppet module install puppetlabs-apt --version 2.4.0
puppet module install garethr-docker
SHELL
config.vm.provision "puppet"
end
If your goal is just to have docker installed on the VM, the easiest is to let vagrant install it. Vagrant has docker provisioner and if not installed it will try to install
This simple Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision "docker"
end
will install docker on trusty64 - the provisioner has after many advantages if you want to work with docker images etc ...
I've used virtual box and vagrant previously for a ruby on rails dev environment with the same configurations perfectly fine. I just upgraded to windows 10 and reinstalled vagrant along with virtual box. When I run the command
vagrant up
I get the following error.
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty64'...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["import", "C:/Users/canno/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/20160714.0.0/virtualbox/box.ovf", "--vsys", "0", "--vmname", "ubuntu-cloudimg-trusty-vagrant-amd64_1469803400806_80416", "--vsys", "0", "--unit", "6", "--disk", "C:\\Users\\canno\\VirtualBox VMs\\ubuntu-cloudimg-trusty-vagrant-amd64_1469803400806_80416\\box-disk1.vmdk"]
Stderr: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Interpreting C:\Users\canno\.vagrant.d\boxes\ubuntu-VAGRANTSLASH-trusty64\20160714.0.0\virtualbox\box.ovf...
OK.
0%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage.exe: error: Appliance import failed
VBoxManage.exe: error: Could not create the imported medium 'C:\Users\canno\VirtualBox VMs\ubuntu-cloudimg-trusty-vagrant-amd64_1469803400806_80416\box-disk1.vmdk' (VERR_ZIP_ERROR)
VBoxManage.exe: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component ApplianceWrap, interface IAppliance
VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleImportAppliance(struct HandlerArg *)" at line 877 of file VBoxManageAppliance.cpp
Here is my vagrant file
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 3000, host: 3000
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# Customize the amount of memory on the VM:
vb.memory = "2048"
end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline <<-SHELL
# sudo apt-get install apache2
# SHELL
config.vm.provision "shell", privileged: false, path: "provision.sh"
end
Here is my provision.sh file
#!/bin/bash
#
# Set up Scott's favorite prompt.
#
echo "export PS1='[\u#\h:\w]\n\$ '" >> ~/.bashrc
#
# Set up case-insensitive autocompletion.
#
echo "shopt -s nocaseglob" >> ~/.bashrc
echo "set completion-ignore-case On" > ~/.inputrc
#
# Install the requisite Ubuntu packages.
#
sudo apt-get update
sudo apt-get -y install git libyaml-dev libxslt-dev libxml2-dev libsqlite3-dev nodejs-dev
#
# Install RVM.
#
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable
#
# Use RVM to install the latest Ruby 2.2 release.
#
~/.rvm/bin/rvm --quiet-curl install ruby-2.2
#
# Make a symbolic link to the synced directory.
#
ln -s /vagrant ~/workspace
I have searched all over the internet for a solution to this problem but I have been unable to find anything that works. It does appear that this is a known issue that may have something to do with missing c++ files, but everything there I have tried hasn't worked either. Any help would be very appreciated. Thanks in advance!
I'm new to vagrant, using 1.7.4 with VirtualBox 5.0.10 on Windows 7 and trying to figure out how to get it to setup and run docker containers the way I'd like, which is like so:
Start my docker host, which is already provisioned with the latest docker tools and boots with the cadvisor container started - I get this box from the publicly available williamyeh/ubuntu-trusty64-docker
If (for example) the mongo container I'd like to use has not been created on the docker host, just create it (don't start it)
Else, if the container already exists, start it (don't try to create it)
With my current setup, using the docker provider, after the first use of vagrant up, using vagrant halt followed by vagrant up will produce this error:
Bringing machine 'default' up with 'docker' provider...
==> default: Docker host is required. One will be created if necessary...
default: Docker host VM is already ready.
==> default: Warning: When using a remote Docker host, forwarded ports will NOT be
==> default: immediately available on your machine. They will still be forwarded on
==> default: the remote machine, however, so if you have a way to access the remote
==> default: machine, then you should be able to access those ports there. This is
==> default: not an error, it is only an informational message.
==> default: Creating the container...
default: Name: mongo-container
default: Image: mongo
default: Port: 27017:27017
A Docker command executed by Vagrant didn't complete successfully!
The command run along with the output from the command is shown
below.
Command: "docker" "run" "--name" "mongo-container" "-d" "-p" "27017:27017" "-d" "mongo"
Stderr: Error response from daemon: Conflict. The name "mongo-container" is already in use by container 7a436a4a3422. You have to remove (or rename) that container to be able to reuse that name.
Here is the Vagrantfile I'm using for the docker host:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.hostname = "docker-host"
config.vm.box_check_update = false
config.ssh.insert_key = false
config.vm.box = "williamyeh/ubuntu-trusty64-docker"
config.vm.network "forwarded_port", guest: 27017, host: 27017
config.vm.synced_folder ".", "/vagrant", disabled: true
end
...and here is the docker provider Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider "docker" do |docker|
docker.vagrant_vagrantfile = "../docker-host/Vagrantfile"
docker.image = "mongo"
docker.ports = ['27017:27017']
docker.name = 'mongo-container'
end
end
Well, I'm not sure what had gotten munged in my environment, but while reconfiguring my setup, I deleted and restored my base docker host image, and from that point on, vagrant up, followed by vagrant halt, followed by vagrant up on the docker provider worked exactly like I was expecting it to.
At any rate, I guess this question is already supported by vagrant.
I'm trying to build a docker container on the fly in a vagrant vm. The Vagrantfile and Dockerfile the container is to be built from are in the same directory, and on the VM, they are both found in the default synced folder /vagrant as expected. Unfortunately, building the container does not work- I get The Dockerfile (Dockerfile) must be within the build context. What is the proper build context in this case? Do I need to copy the Dockerfile somewhere to be able to use it?
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox"
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "ubuntu"
config.vm.network :private_network, ip: "192.168.0.200"
config.ssh.forward_agent = true
config.ssh.insert_key = false
config.vm.provision "docker" do |d|
d.build_image "/vagrant/Dockerfile"
d.build_args = ['--tag "container"']
d.run "container"
end
end
Output:
$ vagrant provision
==> default: Running provisioner: docker...
==> default: Building Docker images...
==> default: -- Path: /vagrant/Dockerfile
==> default: stdin: is not a tty
==> default: The Dockerfile (Dockerfile) must be within the build context (/vagrant/Dockerfile)
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
docker build /vagrant/Dockerfile
Stdout from the command:
Stderr from the command:
stdin: is not a tty
The Dockerfile (Dockerfile) must be within the build context (/vagrant/Dockerfile)
The d.build_image "/vagrant/Dockerfile" option should refer to the containing folder of the Dockerfile, in this case:
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox"
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "ubuntu"
config.vm.network :private_network, ip: "192.168.0.200"
config.ssh.forward_agent = true
config.ssh.insert_key = false
config.vm.provision "docker" do |d|
d.build_image "/vagrant"
d.build_args = ['--tag "container"']
d.run "container"
end
end
I am using:
Windows 8 64-bit
vagrant 1.7.2
Virtual Box 4.3.28
GitBash 1.9.4 for SSH connection
Box Ubuntu 14:04:02 Trusty32 and
Box Ubuntu 14:04:02 Trusty64
I am using everioment development ruby on rails on ubuntu/trusty32 and trusty/64 on vagrant to windows64.
Everything is worked well, but i don`t can share the folders on windows between vagrant.
This is my Vagrant File:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "trusty64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end
Trusty64 on windows does not connect.
Trusty32 on Windows ok, but does not share.
I've had this problem on a similar configuration and this fixed it:
vagrant ssh
sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
exit
vagrant reload
I solved the problem by using another box I found in vagrantcloud.
First set up in Mac after everything working, I fathered a litter box (package) and went pro Windows8, did the normal procedure and it worked!
I recomento that use 64bit, Window32 not support nfs, and enable virtualization in bios.