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.
Related
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
I have a custom boot2docker with this configuration attached to the .iso
config.vm.provider "virtualbox" do |v|
v.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 0, '--device', 0, '--type', 'dvddrive', '--medium', File.expand_path("../boot2docker.iso", __FILE__)]
v.customize ['modifyvm', :id, '--nictype1', 'virtio']
end
config.vm.network "private_network", ip: "192.168.10.10", id: "default-network", nic_type: "virtio"
My files in the directory
mycompany/
dockerhost/
Vagrantfile
Vagrantfile
The vagrantfile of the docker-host that replaces the above.
## This is required with the plugin winnfsd
config.vm.network "private_network", type: "dhcp"
config.vm.synced_folder "../", "/vagrant", type: "nfs"
When I start up the dockerhost with vagrant up it works well and the NFS is setup correctly, but when I start a service container vagrant up myservice
shows the error
==> myservice: Docker host is required. One will be created if necessary...
myservice: Docker host VM is already ready.
==> myservice: Syncing folders to the host VM...
dockerhost: Mounting shared folders...
dockerhost: /var/lib/docker/docker_1472079332_51007 => C:/Users/myuser/Desktop/mycompany
Vagrant was unable to mount VirtualBox shared folders. This is usually because the filesystem "vboxsf" is not available. This filesystem is made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attemped was:
set -e
mount -t vboxsf -o uid=`id -u docker`,gid=`getent group docker | cut -d: -f3` b5973a5087 /var/lib/docker/docker_1472079332_51007 mount -t vboxsf -o uid=`id -u docker`,gid=`id -g docker` b5973a5087 /var/lib/docker/docker_1472079332_51007
The error output from the command was:
mount: mounting b5973a5087 on /var/lib/docker/docker_1472079332_51007 failed: Protocol error
It looks like Vagrant mount another volumen when starts a container.
Any idea about how to fix it?
or why vagrant mounts another for my?
Tks
Vagrant and VirtualBox version incompatibility problems
This fix my problem:
Vagrant 1.8.5 should be compatible with the latest VirtualBox 5.1.2 release, however VirtualBox Guest Additions version we currently have is 5.0.20 and the latest boot2docker release is at 5.0.24. Both will most likely have issues with VirtualBox 5.1.2.
So for now avoid VirtualBox 5.1.x and stick with:
Vagrant 1.7.4 - 1.8.4
VirtualBox 5.0.x
Reference:
https://github.com/blinkreaction/boot2docker-vagrant/issues/83
I am running Vagrant on Mac OS X. I have created following Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/vagrant", disabled: true
config.ssh.insert_key = true
config.vm.provider "docker" do |doc|
doc.image = "httpd"
doc.ports = ["80:80"]
doc.name = 'apache'
doc.remains_running = true
doc.has_ssh = false
end end
It is starting, however I can't execute following command:
vagrant docker-exec -dt apache -- /bin/bash
I have also tried to change apache into container ID, but have failed too.
The container is running as I can check it in Virtualbox.
I can only see that I have vagrant docker-logs and vagrant docker-run, but the documentation of Vagrant says that there should be docker-exec.
Any ideas?
-i --interactive is required if you want a bash shell you can type in.
-d --detach will not work for typing either as the process will be in started in the background.
Use vagrant docker-exec -it apache -- /bin/bash
Yep, that is correct. I also know now that you need to do list-commands to see this docker-exec command.
thank you
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.