When I reboot vagrant box from inside it with sudo /sbin/shutdown -r now synced folders remain empty.
How can I manage remounting synced folders?
you should run vagrant reload from the host; if you reboot from the VM sync folder will not be remount as it needs to be done from the host
If the reboot is done automatically and after its done you will need to issue the mount command yourself
sudo mount -t vboxsf <name of shared> <path>
for example
sudo mount -t vboxsf vagrant /vagrant/
As a workaround, re-mount the volumes, e.g.:
sudo mount -a
Related
When I try to run a container on OSX (with docker-machine on a Parallels VM) and mount a volume located in /tmp the volume seems empty.
> mkdir -p /tmp/foo/bar
> docker run -ti -v /tmp/foo:/foo ubuntu ls /foo
I expect to see it list bar, however, it's empty. This works:
> mkdir -p /Users/myuser/tmp/foo/bar
> docker run -ti -v /Users/myuser/tmp/foo:/foo ubuntu ls /foo
bar
The same happens with folders created with mktemp which end up in /folders. How can I make docker mount those folders correctly?
This is a well known problem.
The reason behind this is linked to the VM, when it's created it mounts the folders within your Users directory, which makes it the only folder available to the containers.
Here is the similar issue
https://github.com/docker/kitematic/issues/1192
As a workaround, you can simply add the desired location(s) to the underlying VirtualBox machine. If your docker machine is default and you would like to be able to mount external volumes, you can use:
VBoxManager sharedfolder add default --name Volumes --hostpath /Volumes --automount
Afterwards, docker run -v /Volumes/Data:/mnt/Data ls /mnt/Data will work.
It's 2022 and I found myself in the same situation. Additional information that may be useful is: /tmp -> /private/tmp is a symlink (OSX) that may be causing a problem. In docker run command in volumes I replaced /tmp with /private/tmp and it works!
I'm doing server side development and my workspace is located in D: because I'm not a fan of storing data on C: but just can't find a way to map d:\Workspace to /home/workspace
I've tried creating a symblink from C:\Users\username to D:\Workspace by:
map C:\Users\username\Workspace to /home/workspace
Stop container
rename C:\Users\username\Workspace
Create symlink named Workspace to D:\Workspace
Start container
At first Docker worked fine during that session until I restart Boot2Docker, then start the container I'd get "C:\Users\username\Workspace file exists".
I think this is one Docker's issue but anyways I want to map outside C:\Users.
Share workspace between host and Boot2Docker virtual machine
$ boot2docker down
$ cd "C:\Program Files\Oracle\VirtualBox"
$ VBoxManage sharedfolder add boot2docker-vm --name mydata --hostpath "D:\Workspace"
$ boot2docker up
Mount shared folder
$ boot2docker ssh 'sudo mkdir -p /data'
$ boot2docker ssh 'sudo mount -t vboxsf -o "defaults,uid=33,gid=33,rw" mydata /data'
Create data-only container. Docker best practices always recommends you use data-only containers. You can reuse already available data-only containers:
$ docker run --volume /data:/data --name mydata dylanlindgren/docker-laravel-data
If you want this change to be permanent, you need to add last command inside startup config file /var/lib/boot2docker/bootlocal.sh
sleep 10 && sudo mount -t vboxsf -o "defaults,uid=33,gid=33,rw" mydata /data
docker start mydata
Then, you will have your workspace mounted at /data
You can find more documentation about VirtualBox Guest Additions in Boot2Docker here.
Updated answer for now, as boot2docker has been deprecated.
The same is now achieved with docker-machine.
The answer is described here: https://github.com/docker/machine/issues/1814
Basically, after mounting the shared folders in the Virtual Box UI, you need to run the following commands in a command prompt:
# Note the extra / at the beginning of the path because of msys/MinGW.
docker-machine.exe ssh default 'sudo mkdir --parents //e/Documents/workspace'
docker-machine.exe ssh default 'sudo mount -t vboxsf e/Documents/workspace //e/Documents/workspace'
I'm running boot2docker 1.3 on Win7.
I want to connect a shared folder.
In the VirtualBox Manager under the image properties->shared folders I've added the folder I've want and named it "c/shared". The "auto-mount" and "make permanent" boxes are checked.
When boot2docker boots, it isn't mounted though. I have to do an additional:
sudo mount -t vboxsf c/shared /c/shared
for it to show up.
Since I need that for every time I'll ever use docker, I'd like that to just run on boot, or just already be there. So I thought if there were some startup script I could add, but I can't seem to find where that would be.
Thanks
EDIT: It's yelling at me about this being a duplicate of Boot2Docker on Mac - Accessing Local Files which is a different question. I wanted to mount a folder that wasn't one of the defaults such as /User on OSX or /c/Users on windows. And I'm specifically asking for startup scripts.
/var/lib/boot2docker/bootlocal.sh fits your need probably, it will be run by initial script /opt/bootscripts.sh
And bootscripts.sh will also put the output into the /var/log/bootlocal.log, see segment below (boot2docker 1.3.1 version)
# Allow local HD customisation
if [ -e /var/lib/boot2docker/bootlocal.sh ]; then
/var/lib/boot2docker/bootlocal.sh > /var/log/bootlocal.log 2>&1 &
fi
One use case for me is
I usually put shared directory as /c/Users/larry/shared, then I add script
#/bin/bash
ln -s /c/Users/larry/shared /home/docker/shared
So each time, I can access ~/shared in boot2docker as the same as in host
see FAQ.md (provided by #KCD)
If using boot2docker (Windows) you should do following:
First create shared folder for boot2docker VM:
"C:/Program Files/Oracle/VirtualBox/VBoxManage" sharedfolder add default -name some_shared_folder -hostpath /c/some/path/on/your/windows/box
#Then make this folder automount
docker-machine ssh
vi /var/lib/boot2docker/profile
Add following at the end of profile file:
sudo mkdir /windows_share
sudo mount -t vboxsf some_shared_folder /windows_share
Restart docker-machine
docker-machine restart
Verify that folder content is visible in boot2docker:
docker-machine ssh
ls -al /windows_share
Now you can mount the folder either using docker run or docker-compose.
Eg:
docker run it --rm --volume /windows_share:/windows_share ubuntu /bin/bash
ls -al /windows_share
If changes in the profile file are lost after VM or Windows restart please do following:
1) Edit file C:\Program Files\Docker Toolbox\start.sh and comment out following line:
#line number 44 (or somewhere around that)
yes | "${DOCKER_MACHINE}" regenerate-certs "${VM}"
#change the line above to:
# yes | "${DOCKER_MACHINE}" regenerate-certs "${VM}"
Thanks for your help with this. An additional few flags I needed to add, in order for the new mount to be accessible by the boot2docker "docker" user:
sudo mount -t vboxsf -o umask=0022,gid=50,uid=1000 Ext-HD /Volumes/Ext-HD
With docker 1.3 you do not need to manually mount anymore. Volumes should work properly as long as the source on the host vm is in your user directory.
https://blog.docker.com/2014/10/docker-1-3-signed-images-process-injection-security-options-mac-shared-directories/
I can't make it work following Larry Cai's instruction. I figured I could make changes to "c:\Program Files\Boot2Docker for Windows\start.sh", add below
eval "$(./boot2docker.exe shellinit 2>/dev/null | sed 's,\\,\\\\,g')"
your mount command
eval "$(./boot2docker ssh 'sudo mount -t vboxsf c/shared /c/shared')"
I also add the command to start my container here.
eval "$(docker start KDP)"
So I'm setting up a vagrant environment for our small team of 4 developers. I'm using an Ubuntu/Precise32 box and I created a shell script for provisioning with lots of apt-get and cp calls. Something like this:
#!/bin/bash
#filename: provision.sh
sudo apt-get update
apt-get install debconf-utils -y > /dev/null
debconf-set-selections <<< "mysql-server mysql-server/root_password password myPassword"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password myPassword"
sudo apt-get install -y vim apache2 mysql-server-5.5 mysql-client git sqlite python-pip phpmyadmin
sudo pip install virtualenv
sudo pip install Django==1.4
sudo a2enmod rewrite
sudo service apache2 restart
echo "Copying hosts ..."
sudo cp /vagrant/hosts /etc/
echo "Copying .gitconfig ..."
sudo cp /vagrant/.gitconfig /home/vagrant/
echo "Copying .bashrc ..."
sudo cp /vagrant/.bashrc /home/vagrant/
echo "Copying .bash_aliases ..."
sudo cp /vagrant/.bash_aliases /home/vagrant/
sudo ln -fs /usr/share/phpmyadmin /var/www
if [ ! -d "/vagrant/projects" ]; then
echo "Creating folder /vagrant/projects"
mkdir /vagrant/projects
fi
cd /vagrant/projects
#git clone myServer:/git/project.git
#can't clone because the user is vagrant. tries ssh vagrant#myServer asking for a password
Now I would like to clone some git repositories (from our own servers) if they don't already exist. But within the provision the active user is vagrant and I don't want to create a vagrant user on our git server or any other servers that we could use.
Each developer in the team already have their ssh accounts on other servers. So should I just create all the users in all the vagrant boxes? And if so, how can they ssh into other servers with no password?
I don't want the developers (myself included) to make user management on their own vagrant box (stuff like adduser, ssh-copy-id etc...). I want to provision everything like cloning git repositories and maybe rsync'ing but I want to be able to set up the right user for different vagrant boxes.
I want to be able to do this from shell provision:
If Vagrant box 1 => create user developer1 that already has passwordless ssh access to our servers
If Vagrant box 2 => create user developer2 that already has passwordless ssh access to our servers
If Vagrant box 3 => create user developer3 that already has passwordless ssh access to our servers
If Vagrant box 4 => create user developer4 that already has passwordless ssh access to our servers
Thank you!
I don't know the answer, but hopefully I may be able to point you in the direction of a possible solution.
I'm guessing the /vagrant share will point to the host in your setup, in which case you could store that information in the project folder on the individual developer's machines and then call / use it in the provisioning setup.
Alternatively, try using 'Socket.gethostname' in the vagrant file - in Ruby it returns the host computer's name, so you could use this to sniff which on which developer's machine the vagrant file is running.
i.e.
if Socket.gethostname === 'Developer1PC'
end
if Socket.gethostname === 'Developer2PC'
end
if Socket.gethostname === 'Developer3PC'
end
if Socket.gethostname === 'Developer4PC'
end
You'll have to excuse any ruby errors, I'm not a ruby dev, but I've just had to do something along similar lines in Vagrant.
I'm asking so I don't have to "cd" everytime I use Vagrant. Thanks.
You can add cd dir-name to your .bashrc file inside your vm. So once you ssh into your vagrant machine it'll automatically run and change the directory.
On ubuntu .bashrc file is located in home (/home/vagrant) directory.
Alternatively you can connect to your vagrant box through starndard ssh command. This will allow you to specify the directory name at the connect time and have more freedom.
For example
ssh -p 2222 vagrant#localhost -t "cd dir-name ; /bin/bash"
You can see vagrant ssh config using below command. So you can check your port, user.. etc.
vagrant ssh-config