Volume sharing in Docker and Virtualbox - windows

I have installed docker toolbox on my Windows PC,when i install containers on it using Kitematic, I want to share a folder with my local machine. However docker runs in virtualbox on the default machine in VirtualBox.
So, i guess i first have to do a fvolume share of the virtualbox vm with my local machine and then a second share of the docker container with the folder that I shared in virtualbox. Could someone assist me in this please?

No, you shouldn't need to share any more folder: docker-machine will create a VM which auto-mount C:\Users\<yourLogin>.
docker-machine ls
docker-machine ssh default
cd /C/Users/<yourLogin>
You can mount other folders from your hosts, but you don't have to.

I'm running docker version 18.03.0 ce on Windows 10, and the C:\Users folder is shared as /c-users on the docker VM (default), so using the command line
docker run -it -v /c-users/my_windows_user/project:/media/project ubuntu:16.04 bash
I can access the Windows project files from /media/project within the Ubuntu container

Related

Run Virtualbox inside docker container, on Windows host

I know this is not what docker containers should be used for, but hear me out. I'm trying to port over a local environment that is currently run on Windows 10 with Chef, Vagrant & Virtualbox.
I believe it is possible to do this in Ubuntu by installing Virtualbox on the host, then mounting the /dev/vboxdrv directory into the container. While there is a vboxdrv directory for the Windows installation C:\Program Files\Oracle\VirtualBox\drivers\vboxdrv, it won't work for a Linux-based container.
Is it possible to get Virtualbox running inside of a Docker container while on a Windows host? I doubt it, but thought I'd ask to confirm in case I had missed some nice workaround.

Connecting Docker Windows WSL Ubuntu to VMware Ubuntu

I am trying to connect my Windows 10 Home system to be able to run full Linux OS Docker containers. I have installed Docker on both WSL Ubuntu 18.04 as well as a VMware Ubuntu 18.04.
I was trying to follow this guide.
However, I get stuck trying to configure the Daemon as per the instructions.
Can’t use Docker for Windows?
This is only necessary if you are NOT running Docker for Windows!
No problem, just configure your Docker daemon to use -H tcp://0.0.0.0:2375 and --tlsverify=false. Then you can follow along with the rest of this guide exactly.
If you go down this route, I highly recommend rolling your own VM with VMware Player instead of using the Docker Toolbox because VirtualBox has crazy edge case shared folder bugs that will ruin your life at some point. Don’t worry, VMware Player is free. Just Google how to set up Ubuntu 16 server on VMware Player.
When I try to change the Docker Daemon by making a daemon.json file I get errors. I've also tried editing the .profile files and the .bashrc as per other guides (another guide), with no luck.
I am unable to check the DOCKER_HOST variable on the VM Ubuntu.
Don't make things complicated. In your case, why WSL if you just want to connect to a remote daemon? Why not simply use the windows docker client?
Setup you favorite local VM with docker.
Example: I have installed a CentOS distro running on local VMWare Workstation. All Hyper-V of course deinstalled/deactivated.
In this VM, enable tcp access for the daemon.
If you have a systemd linux distro (like mine CentOS), execute this:
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo echo '[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375' >> /etc/systemd/system/docker.service.d/options.conf
sudo systemctl daemon-reload
sudo systemctl restart docker`
Test if the port is open with docker info. You should get an API access warning at the bottom result.
Download the Windows docker cli zip from here: https://download.docker.com/win/static/stable/x86_64/
Move the docker.exe to any folder, for ex. your Documents folder.
Then put this folder path into your Windows PATH variable.
Set the docker host: Open PowerShell, execute setx DOCKER_HOST <VM-IP>:2375 and close it.
Open a new PowerShell and call docker info.
You should see the docker and daemon infos.
Do what ever you like now... :-)

Can't mount Windows host directory to Docker container

I'm on Windows 10 Pro with Docker Version 1.12.0-rc3-beta18 (build: 5226). I would like use Docker for PHP development on Windows machine. I tried all possible (I hope) variations of mounting host directory into Docker container:
//c/Users/...
/c/Users/...
//C/Users/...
/c/Users/...
c:/Users/...
c:\Users...
"c:\Users..."
Neither of variants launch container. Yes, docker run creates container and I can see it with docker ps --all. But I can't it start. E.g. I tried simple documentation example:
docker run -d -P -v "C:\temp":/opt/webapp training/webapp python app.py
and
docker logs e030ba0f7807
replays as
python: can't open file 'app.py': [Errno 2] No such file or directory
What happened?
If you are using docker with docker-machine, you would need to register c:\temp first as a shared folder in VirtualBox.
See "docker with shared folder d drive"
From within a docker-machine ssh session:
sudo touch /mnt/sda1/var/lib/boot2docker/bootlocal.sh
Add to that file:
mkdir -p /mnt/temp
mount -t vboxsf -o defaults,uid=`id -u docker`,gid=`id -g docker` temp /mnt/temp
That path would then be accessible through /mnt/temp for instance.
The same applies for C:\Users, which is already a shared folder c/Users.
It is accessible with /c/Users.
With Hyper-V, see "Running Docker on Hyper-V" from Henning M Stephansen:
Hyper-V is a more isolated and restrictive environment than VMWare or VirtualBox is, so there’s no concept of shared folders.
However we can mount and access Windows shares from our Docker VM.
The first thing you need to do is to share a folder. This folder can be restricted to just your user.
If the VM has access to the network through an External Virtual Switch or an Internal Virtual Switch you should be able to mount your folder from the docker VM.
To be able to mount a windows share from Boot2Docker/Tiny Core Linux we need to install some additional module (This might be included in your image):
wget http://distro.ibiblio.org/tinycorelinux/5.x/x86/tcz/cifs-utils.tcz
tce-load -i cifs-utils.tcz
Now we can mount the shared folder using the following command
sudo mount -t cifs //HOST-IP-HERE/SharedFolderPath /path/where/we/want/it/mounted -o username=HOST_USERNAME_HERE

How run Docker with sync folder on Windows

Well using Kitematic on Windows and starting the container hello-world-nginx. I'm totally able to edit the file on Windows and see the modifications at the browser.
But when I create some image and try to edit the file (html), nothing happens.
Here's the command:
docker build -t a-example . && docker run --name a-example -i -t -v //c/Users/pablo/htdocs/www/a-example/src:/www -d -p 80:80 a-example
And here's my Dockerfile:
FROM nginx
RUN mkdir /etc/nginx/logs && touch /etc/nginx/logs/a-example.log
ADD ./nginx.conf /etc/nginx/conf.d/default.conf
ADD /src /www
VOLUME /www
Another question:
Is this message have something to do with?
SECURITY WARNING: You are building a Docker image from Windows against
a non-Win dows Docker host. All files and directories added to build
context will have '-r wxr-xr-x' permissions. It is recommended to
double check and reset permissions f or sensitive files and
directories.
I do not use KiteMatic or Docker Machine to control my local docker instance.
However, Docker Machine uses a boot2docker iso (customized version of Tiny Core Linux with Docker) running in a VirtualBox vm. Virtual Box provides guest Additions to mount host machine folders.
Refer to Boot2Docker guidelines at the time of Docker 1.9.1 release
Or the Docker Machine shares:
On Windows:
- C:\Users mounted as /c/Users
On Linux:
- /home mounted as /hosthome
On OSX:
- /Users mounted as /Users
which is done through Guest Additions:
vbm("sharedfolder", "add", d.MachineName, "--name", shareName, "--hostpath", shareDir, "--automount")
If you opt to use samba shares from your windows host instead, you will need the appropriate TLC packages (from the FAQ):
How do I mount windows shares?
If the sharing computer is at least Windows 2000, you can mount the share with only the filesystems-2.6.29.1-tinycore.tcz extension.
In a root console:
mkdir /mnt/windows
mount -t cifs //9.53.216.11/myshare /mnt/windows -o user=myname,pass=mypassword
And after searching for boot2docker and filesystems-2.6.29.1-tinycore.tcz I got to this GitHub issue:
sudo find / -type d -name 'cifs' seems to indicate that CIFS (Samba) client in the right kernel version is already there... allowing us to run
sudo mount -t cifs //MYPC/hostgithub ~/windows -o user=USER
on the boot2docker VM
Using Docker Volumes
It seems Docker Volumes are a new proposal for handling host folders for Developer Environments, see:
Docker-Volume-Netshare: Although this requires nfs-common or nfs-utils (depending on your distro) to be available on the docker machine, this may not work for CoreOS / Boot2Docker without some other tricks.
It should actually work on boot2docker considering how Docker-Volume-Netshare just wraps shell exec /bin/sh -c "mount -t cifs ..." command. If you use the so0k/mount.cifs_copy on CoreOS you may need a way to specify the path to cifs /opt/bin/mount.cifs.
For Windows users, note also my blog post using the netshare volume driver mentioned above to provision mounts from the Windows host across a Swarm Cluster.
Note: Be careful when using git-for-windows and git-bash as I'm having issues with these converting the paths I pass on to docker.exe
I don't think your volume is available so your container is displaying the static content from /src that you ADDed during the image build.
Kitematic runs a VirtualBox linux machine which runs your docker containers.
The path you have used for the volume: //c/Users/pablo/htdocs/www/a-example/src:/www looks suspect as that's the full windows path.
Docker machine (which is what kitematic uses underneath to manage the virutal machine) will map C:\Users to /Users by default
Try --volume /Users/pablo/htdocs/www/a-example/src:/www

How to Setup a Docker Tomcat Container on Mac OS X

I'm new to Docker...
From my understanding, Docker is only compatible with Linux, is it possible to run docker for development purposes on a Mac?
I installed virtualbox using homebrew and have tried to create a virtualbox instance. I installed docker, but am having trouble getting my mac to communicate with the vm docker instance. My end goal is to get a locally debuggable instance of tomcat running on the docker container.
Any help or tips would be helpful.
Information:
Because Docker only runs on Linux you will need to install some kind of virtual instance on your local machine. An easy and popular way to do that is to install
Boot2docker and VirtualBox. VirtualBox is a dependency of Boot2docker. You can download, setup and install the latest versions from their websites or if you are using Homebrew, as you mentioned, you can quickly get the working binaries both in one step.
After installing boot2docker, you're ready to use Boot2docker to create a Tomcat Container. You can find a pre-configured tomcat image by searching Docker's community repository, docker hub registry.
Notes:
Each time you execute the docker run command a new container is created.
The VM running Docker requires a ssh private/public encryption key handshake to connect to. If you follow my steps below, one will be generated for you.
Steps to Setup Tomcat using the tomcat image:
Open Terminal and run this command: brew install boot2docker
Create a new Boot2Docker VM instance using the init command: boot2docker init
Run this command in Terminal to forward local ports to the vm:
for i in {10000..10999}; do VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i”; VBoxManage modifyvm "boot2docker-vm" --natpf1 "udp-port$i,udp,,$i,,$i";done
Start the boot2docker daemon: boot2docker start or boot2docker up
After starting docker, copy the exports that are displayed from the previous command to your clipboard
Edit your bash profile file ~/.bash_profile (or if you are using zsh, edit the resource configuration file ~/.zshrc) with a text editor (I prefer using Sublime text): subl .zshrc *note: this will permanently save the docker env variables.
Paste the exports into that file and save
Execute the source command on the file: source .zshrc
Pull the latest tomcat image to create a container and start tomcat: docker run -it --rm -p 10080:8080 tomcat:8.0 *note: this will forward your local 10080 port to the vm's 8080 port.
Go to http://localhost:10080, you should see the tomcat start page!
Useful Docker commands:
$ boot2docker status
$ docker version
$ docker ps #shows running containers
$ docker ps -a # shows all containers
$ docker exec -it NAME /bin/bash #to start a bash session on the container. -i = interactive, -t = tty
External Resources:
https://docs.docker.com/installation/mac/#installation
https://registry.hub.docker.com/_/tomcat/
Most people use boot2docker to run on Macs. You may also want to take a look at Kitematic, which gives you a GUI to play with.
Finally, the future is probably to use docker machine, which can provision a VM for you.
Docker requires Linux Kernel features, hence it cannot be run natively on OSX.
See instead Boot2Docker. This link gives you instructions on how to get going.

Resources