How do I get Docker to mount VM volumes on OSX - macos

I apologize if this is better on serverfault or ask different, it's not immediately clear to me where this question belongs.
I'm currently running docker for mac and I have a pretty strong understanding of how to mount folders from my OSX host machine inside of running docker containers. My understanding is that docker is achieving this by running a Linux VM and handling the mounting between the VM and the host machine.
What I want to do is mount folders from the VM inside of my running container.
I can sort of accomplish this by running docker from inside of docker:
docker run --privileged \
-it \
-v /var/run/docker.sock:/var/run/docker.sock \
ubuntu-docker-client#sha256:038874e2c9c663550c9ddb0c8eb814c88d8a264cd1a5bfb4305dec9282598094 \
/bin/bash -c "docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v /:/host alpine /bin/sh -c 'chroot /host && /bin/sh'"
This handles the problem by escaping the chroot jail from inside a running container through the use of privileged containers.
I was hoping to find a solution which was less invasive and allowed me to mount volumes from both the host machine (OSX) and the linux VM.

Related

Using audio on a container with Podman, on Mac OS

I'm trying to use audio on a container launched with Podman on MacOS.
The container is jess/pulseaudio
I am using a big Sur OS with an Apple M1 chip ( also tested on an INTEL chip)
I use podman in version 3.4.4
The commmand podman run hello world works well
After launching podman ( podman machine init and podman machine start), I connect with ssh to the VM and install pulseaudio alsa-utils pulseaudio-utils on the VM. Then I launch pulseaudio on the host Mac OS and on the podman VM with the command
pulseaudio --load=module-native-protocol-tcp --exit-idle-time=-1 --daemon
Then I run the following command to launch the container:
podman run -it -e PULSE_SERVER=docker.for.mac.localhost -v /home/core/.config/pulse:/home/pulseaudio/.config/pulse --entrypoint speaker-test --rm jess/pulseaudio -c 2 -l 1 -t wav
and I get this error on my host terminal (the containers is then not launch):
{"msg": "exec container process "/usr/bin/speaker-test": Exec format error","level":"error","time":"2021-12-13T12:40:09.000532852Z"}
when I run the following command
podman run -it -e PULSE_SERVER=docker.for.mac.localhost -v /home/core/.config/pulse:/home/pulseaudio/.config/pulse --rm jess/pulseaudio
I get this error:
{"msg":"exec container process "/usr/bin/pulseaudio": Exec format error","level":"error","time":"2021-12-13T13:00:04.000533324Z"}
I would like to point out that the following command works for me with Docker, on the same macOS:
docker run -it -e PULSE_SERVER=docker.for.mac.localhost -v ~/.config/pulse:/home/pulseaudio/.config/pulse --entrypoint speaker-test --rm jess/pulseaudio -c 2 -l 1 -t wav.
I know that Podman uses a virtual machine on Mac OS. So I think I should first link the audio of the virtual machine with the audio of the MacOS host like when I mount volumes (first I mount the volume on the VM and then on the container) but I'm not sure. Is there some specific podman configuration or command to use audio, or should I do it manually ?
Do you have an idea?

Cannot mount a volume without using sudo

The following command works and mounts the local volume:
sudo docker run -ti -v "$PWD/codebase/realsmart-saml-copy":/var/www/html realsmart-docker_smartlogin bash
The following command does not work and does not mount the volume
docker run -ti -v "$PWD/codebase/realsmart-saml-copy":/var/www/html realsmart-docker_smartlogin bash
For some reason, docker is only able to mount volumes using the sudo command, rendering our local docker environment useless on a colleagues laptop. The same docker-compose file works on my laptop (also a mac, same OS).
Any idea as to what the issue might be with his laptop configuration? Or indeed the docker setup.
(The code extract is to make clear the problem with mounting volumes, the same issue presents itself using a compose.yml file.)
Non working code:
docker run -ti -v "$PWD/codebase/realsmart-saml-copy":/var/www/html realsmart-docker_smartlogin bash
No error messages are displayed, but the results are not as expected as the volume does not mount without using sudo.
Try to see if the user is part of the docker group.
It would make sense that sudo works, but not for the local user, if that local user is not part of the docker group.
The solution for anyone interested.
After upgrading to Docker Desktop Boot2Docker has been replaced.
Steps to fix the issue:
docker-machine rm machine-name
unset DOCKER_TLS_VERIFY
unset DOCKER_CERT_PATH
unset DOCKER_MACHINE_NAME
unset DOCKER_HOST
restart Docker Desktop
cd path/to/docker-project.
docker-compose build
docker-compose up (or docker run)
project now available on localhost
Further details: https://docs.docker.com/docker-for-mac/docker-toolbox/
Add your user to the docker group.
sudo usermod -aG docker $USER

ubuntu 18.04 docker container

i'm runnung docker on windows 10 desktop. i like to run ubuntu 18.04 docker container. i have pulled ubuntu and ran following docker command
Docker up -d ubuntu
i'm not seeing image running when i check
docker ps
instead i see image stopped when i check
docker ps -a
why it is like this.? like other images i should see ubuntu running when i check
docker ps
just like wordpress or mysql images.
also i like to mount volume to ubuntu container by using -v tag. let me know if following command is correct or not
docker up -d --name ubuntu -p 80:80 -p 22:22 -v /ubuntu:/home ubuntu

docker sharing host directory

I used to share my host diretory with a docker container with the command (osx):
docker run --name tensorflower -it -p 8888:8888 -v /c/foo/labs:/home tensorflow/tensorflow
on windows it used to work with:
docker run --name tensorflower -it -p 8888:8888 -v //c/foo/labs:/home tensorflow/tensorflow
But now it does not work on windows. I tried both -v variants. As I do not get any error messages, I have no glue where to dig in to solve the problem.
How can I share the host directory c:\foo\labs with my docker container?
Or at least get some more informaton regarding the error?
Docker version 17.09.1-ce, build 19e2cf6 on windows 10

Keyboard/Mouse are unresponsable when running x-org in a docker container

I want to create a docker image for a GUI application (e.g. Chrome) and I hope this GUI app could run at a bare Linux server without X server installed.
I know it is very easy to create and run a docker image just for X Window Client (The GUI application itself). This needs X server be installed and run at host.
sudo docker run -ti -v /tmp/.X11-unix:/tmp/.X11-unix xorg xterm -display :0
But for me, I need both X client and server run in docker container.
Here's my dockerfile:
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y xorg
And I run the image by command:
sudo docker run -i -t --rm -e DISPLAY=:0 --privileged xorg xinit
The X server could be started and my screen turns black, after a few seconds, the xterm window displays. BUT, I can't use keyboard and mouse. The screen seems like freezen
I have searched and tried many solutions but no one could fix this problem. (the virtual x-server is not I needed)
I have resolved this problem.
At first, I thought maybe x server in docker container cannot access host devices, and I spent much time on LXC/cgroup. For example, I changed the docker exec engine to LXC, and I added option '--lxc-conf='lxc.cgroup.devices.allow = c 13:* rwm', and I also created /dev/input/* in container.
All of these operations are unnecessary.
If we run docker container in privileged mode, all host devices will be added automatically. Or we can use options like '--device=/dev/input/mice' to share host device.
The real problem is that x server could not discovery and add device automatically. I don't know why. But we could modify x server's configuration and customize the device.
add file /etc/X11/xorg.conf.d/10-input.conf
Section "ServerFlags"
Option "AutoAddDevices" "False"
EndSection
Section "ServerLayout"
Identifier "Desktop"
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
EndSection
Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "Device" "/dev/input/event2"
EndSection
Section "InputDevice"
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/input/mice"
Option "ZAxisMapping" "4 5 6 7"
EndSection
and run docker container:
docker run -i -t -v /tmp/.X11-unix:/tmp/.X11-unix --rm --privileged ubuntu startx
At first make sure that proper input modules are installed:
RUN DEBIAN_FRONTEND='noninteractive' apt-get install -y --no-install-recommends xserver-xorg-input-evdev xserver-xorg-input-all
In modern Linux udev is responsible for managing device nodes (including USB keyboards) in the /dev tree. It uses /run/udev/data which isn't available inside your container even with -privileged option.
So you need to mount that folder explicitly using -v /run/udev/data:/run/udev/data like this:
docker run -i -t -v /tmp/.X11-unix:/tmp/.X11-unix --rm --privileged -v /run/udev/data:/run/udev/data ubuntu startx

Resources