How to run a .sh fallback on vagrant using a docker vendor
I have used the tramp successfully on many clouds.
I decided to try something with docker, but I was probably missing something very basic as I am failing tremendously.
I wrote this vagrant file:
Vagrant.configure("2") do |config|
config.vm.synced_folder "../synced_folder", "/vagrant"
config.vm.provision "shell" do |s|
s.path = "provision.sh"
s.privileged = false
end
config.vm.provider :docker do |docker, override|
docker.image = 'ubuntu'
end
end
this configuration worked for me for other clouds (if I add the specific cloud details to it, of course).
My file provision.sh
just hasecho "hello world"
my synced_folder has a dummy file.
I have verified that the image ubuntu
works fine in docker. Docker seems to be working fine.
When I run vagrant up --provider docker
I get the following
The container started either never left the "stopped" state or
very quickly reverted to the "stopped" state. This is usually
because the container didn't execute a command that kept it running,
and usually indicates a misconfiguration.
If you meant for this container to not remain running, please
set the Docker provider configuration "remains_running" to "false":
config.vm.provider "docker" do |d|
d.remains_running = false
end
I can't see the printout hello world
.
I found a lot of Q&A regarding this error but couldn't use anything to solve my problem.
What am I doing wrong?
source to share
So, I am missing something very fundamental.
The solution I found is easy. Use this awesome contribution:
https://github.com/bubenkoff/vagrant-docker-example
The important thing to note here is the Dockerfile, which defines the SSH connection in the container. Without SSH, it just won't work.
However - another tacit fact that people are missing - docker uses a socket which requires permissions, however runnign sudo vagrant up --provider
won't fix the problem. in order to run without problems, you must sudo su -
first OR add your user to the group docker
.
More on this: https://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo
So, let's summarize:
- clone git repository
- sudo su -
- vagrant up --provider docker
==> the machine is up and running fine.
source to share
Tried the same thing after https://github.com/mitchellh/vagrant/issues/3951 for a while. It looks like this should be fixed with an upcoming minor Vagrant release.
source to share
config.vm.provider :docker do |docker, override|
docker.image = 'ubuntu'
end
You are missing a command here, you need a command to start the container. something like that:
config.vm.provider :docker do |docker, override|
docker.image = 'ubuntu'
docker.run = 'ubuntu'
end
Or you can do something like this:
config.vm.provider :docker do |docker, override|
docker.image = 'ubuntu'
docker.cmd = ["/usr/sbin/sshd", "-D"]
end
source to share