Pass docker directory as a maven parameter - maven

I have a maven goal that requires the server home folder as a parameter. On my local i just do:
mvn test -Dserverhome=/Users/foo/MyServer
On the test machine, the server is inside a docker container. How do i point to my server directory that is inside a docker container?

You need to mount your host folder as a data volume
docker run -d -P --name aname -v /Users/foo/MyServer:/myserver yourImage
That way, your maven command can always be (within the container)
mvn test -Dserverhome=/myserver
Because you trust that, at runtime, /myserver will have been associated with the right host folder.
Note that if you are using docker on Mac or Windows, /Users is already mounted (by VirtualBox and by boot2docker tinycore Linux), so you would not even need to declare the data volume.

Related

docker mounting folder not working for Windows 10 with WSL2

I have tried this example out on a windows 10 box which has WSL2 installed and integrated with the latest Docker version. After following the steps in the example and downloading the code in the linux subsystem, I am able to build the image and run the container. The website is also available on the browser when I browse to it on a browser running on Windows 10. However, when I create a file or folder in the container the same doesn't reflect in the host filesystem which in this case is the linux subsystem. Similarly, a file created in the host linux subsystem is not seen in the container's cli when I use the ls command.
I ran this commands to confirm that the folder has been mounted where 44711fc95366 is my container id
docker inspect -f "{{ .Mounts }}" 44711fc95366
This gives an output like so:
[{bind /home/userlab1/my-proj/getting-started/app /usr/src/app true
rprivate}]
If the mount point expressed above is correct, I should be able to create a file or folder in host subsystem on the path /home/userlab1/my-proj/getting-started/app and be able to see it at the /usr/src/app path in the container, correct?
The docker image has been created and run from the linux subsystem command line like so:
docker run -it -v ~/my-proj/getting-started/app:/usr/src/app -p 3001:3000 --name cntr-linux-todo
img-todo:in-linux
While the application runs, the files updated in the container don't reflect on the website that is running from the container, nor does a new file/folder created in the container be seen in the host subsystem and vice versa. What am I missing?
As you are using Windows's version of docker, it cannot see files/folders from WSL.
You can move ~/my-proj into C:\Users\user20358, and mount from there :
-v 'C:\Users\user20358\my-proj\getting-started\app:/usr/src/app'

How to access /var/lib/docker in windows 10 docker desktop?

Installed docker desktop for windows 10
Used powershell to run docker containers ( ubuntu )
Now, I want to browse to /var/lib/docker --> want to browse to overlay2 to check layers.. /diff folder etc.
If i access /var/lib/docker folder - powershell complains that this folder does not exist.
Other piece of info: I have already checked out the disk image location which is mapped for docker desktop. It is a vhdx file.
I was not able to open it with Oracle virtual box - it says it is not a supported version file.
I tried opening in Hyper V manager, the VM is getting listed: DockerDesktopVM.
But my objective is to do SSH and browse /var/lib/docker folders..
(This is for case of WSL2. It is my answer to a similar question)
Docker images are managed by docker's own VM. The path /var/lib/docker given by "docker info" is relative to docker's host file system, not your container's file system. The mount points are different for them. You can view docker's host file system in either of the following ways:
You can mount the host file system to a container directory. Such as,
docker run -v /:/data -it ubuntu /bin/bash
This command runs a shell in Ubuntu docker image, mounting docker's file system to /data directory. There you can find a complete file system under /data, including the ./var/lib/docker. If you want, you can "chroot /data" in the shell prompt to have a better view.
When docker is enabled with your distribution in WSL2, you can always check your containers in your distribution /mnt directory. Docker has mounted everything for you.
/mnt/wsl/docker-desktop-data/data/docker
If you are seasoned enough, you may find the actual location of the virtual disk of all the data in your Windows directory.
C:\Users\your_name\AppData\Local\Docker\wsl\data\
Or probably just for fun:
\\wsl$\Ubuntu\mnt\wsl\docker-desktop-data\data\docker
Unfortunately I haven't tried to dive into them.
As stated on This page of docker forums you can run plain debian docker image with shell and change it's namespace to docker host.
The terminal command you need to run is:
>> docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -i sh
as I understand after running debian image as terminal (-it option), you need to call command nsenter with specified parameters to change namespace to host machine. After this your container becomes Docker host and you can view all it's files.
after this command you can access docker images simply by calling:
>> cd ls /var/lib/docker/
In the left pane of your windows file explorer, you can find all you computer drives. If you have installed WSL (when you setup your Docker), you will see this Linux pinguin icon.
Select the docker-desktop-data directory and inside it, the data directory. Within the data directory you will find there the docker directory and the volume generated by docker run ... -v command.
shortcut would be: cd \\wsl.localhost\docker-desktop-data\data

How to access a file of Mac from Docker container

I am running robot framework (Selenium based) testing inside a Docker container. But I need to access files outside the Docker container (in Mac).
I have tried providing absolute path of the Mac but Docker refers it's core folder as the root folder.
I found below links for Windows, but not for Mac.
Docker - accessing files inside container from host
Access file of windows machine from docker container
one approach is copy your files inside docker container at creation time, but if your files updates by another service on host, and it needs to access them too, just mount it like below.
docker run -d --name your-container -v /path/to/files/:/path/inside/container containername:version
this way files on the host machine mounts into docker container and the user inside container can access them.

Mounting directory from windows machine to OracleVMBox for Tensor on Docker

I set up a shared folder "tensor" between my Windows machine and the Oracle VM Virtual box called "default". [I run Windows 7, am using Oracle VM Virtual Box Manager, and the Docker Toolbox.]
Then, I open the Docker Toolbox Quickstart terminal, ssh into "default" VM Box, and can successfully mount the tensor folder into it's directory, like so:
I created "hello_world.txt" on my local computer and the file displayed in the VM.
My issue is that I cannot seem to figure out how to have this directory be used when I run the tensorflow image in a container within the default box (also, i am new to this, so please correct me if my terminology here is wrong).
I exit out of the "default" box, and back to my Docker Client terminal. I tried running the following variations of commands (sourced from multiple websites):
docker run -it -p 8888:8888 -p 6006:6006 -v /mnt/tensor:/tensor --name tf gcr.io/tensorflow/tensorflow
This lets me access the Jupyter notebook when i got to http://DEFAULT_IP:8888, but I do not see the "tensor" folder that I expect to see. Instead, the directory is just empty.
However, i assumed in the command above that -v DIRECTORY_VM:DIRECTORY_CONTAINER, so that the first address that I give it is the directory within my default VM, which is to map to a directory inside the container running with the tensor image.
Second trial is that I tried this:
docker run -it -p 8888:8888 -p 6006:6006 -v //c/Users/rebeccak.REBECCAPC/tensor:/tensor --name tf gcr.io/tensorflow/tensorflow
In this case, I provided the path to the "tensor" folder on my local machine instead of the VM Box.
Still no success. Could someone tell me how to do this correctly? Thank you.
Also, when I run "docker inspect CONTAINER_NAME" for one of my attempts, I got this for mounts:
So the "source" folder does not look like the path I specified. Where is this address? Is it on my "default" vm or is it on my daemon client/linux machine?
You did declare a shared folder on VirtualBox, but you still need to properly mount it in your VM.
In your ssh session:
sudo touch /mnt/sda1/var/lib/boot2docker/bootlocal.sh
Add to that file:
mkdir -p /mnt/tensorflow
mount -t vboxsf -o defaults,uid=`id -u docker`,gid=`id -g docker` tensorflow /mnt/tensorflow
Then restart your docker-machine (stop, start)
A -v /mnt/tensor:/tensor should now work.
Check of course that your source folder does exist: that was OP RebeccaK375's issue:
My issue was actually that there was not a "tensor" folder to mount,

share windows folder (other than c/Users/) with docker container (using docker windows client)

Using docker client, is there a way to share a folder in windows with a docker container without having to first share the folder via the Virtual Box VM.
Have understood the need of having a double slash from this and this
Ran the following command from the docker client for windows
docker run -it -v //F/devfolder:/development/windev <imagename> <cmdname>
but when did a ls on /development/windev , it turned out it was empty.
I did not have any problem when I tried mounting the c/Users/username folder via the following command
docker run -it -v //c/Users/username/desktop:/development/windev <image> <command>
and the windev folder listed the contents as I would expect it to be
Tried sharing F/devFolder via Virtualbox GUI and gave full access but still the contents of the folder is not listed.
[I am not using boot2docker but docker-machine]
Is it not possible to share any other folder than the c/Users/ folder? If yes, anything else I need to do to ensure that I can see the contents of the mounted folder?
Not only you have to mount it in your VirtualBox, but you also have to instruct, in your boot2docker TinyCore session that you want that folder visible (once you have done a docker-machine ssh yourMachine):
mount -t vboxsf -o uid=1000,gid=50 your-other-share-name /some/mount/location
I know that you are using docker-machine, and not boot2docker, yet docker-machine is still using a boot2docker.iso VM image based on TinyCore, so this command still applies.

Resources