How to run amd64 image Docker on arm (Raspberry OS) - docker

I have used the docker image Rotating TOR on amd64 architectures with no problem. Now I try to run the same image on Raspberry OS (arm 32 bit) but I have not succeeded.
This is the error when executing the image:
$ docker run -d -p 5566:5566 -p 4444:4444 --env tors=25 mattes/rotating-proxy
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm/v7) and no specific platform was requested
I have tried adding platform linux/adm64 after the run but the image does not work either.
Does anyone know how to run this image on Raspberry OS or is there just no way to do it? Thanks for the help.

That won't work
Docker is a virtualisation platform, not an emulator. It cannot be used to run images from one architecture on another (AMD64 on ARM or vice versa). You need a matching image (or install the ARM version directly on the PI, if there is one).

You can run docker images across platforms with QEMU, which is an emulator.
Docs: https://dbhi.github.io/qus/
Docker images: https://github.com/multiarch/qemu-user-static
You can run QEMU with one of the images maintained at the above link with something like:
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
Which should then allow you to run your x86 images, e.g.:
docker run --rm -t i386/ubuntu uname -m

Related

How to install Memgraph on Mac that has M1 processor?

I'm confused about what I should do to install Memgraph on Mac that has M1 processor. Do I need to run the command docker run -it -p 7687:7687 -p 3000:3000 memgraph/memgraph-platform or should I go to https://memgraph.com/download and download Docker image from that page?
Installing Memgraph on Linux, MacOS and Windows can be achieved by using Docker. There is a bit of difference if we talk about MemgraphDB and Memgraph platform.
If we talk about MemgraphDB there is no difference between downloading Memgraph from download website or pulling from Docker hub.
If you want to pull an image and build a container from the Docker hub, it is enough to run the docker command:
docker run -p 7687:7687 -p 7444:7444 -v mg_lib:/var/lib/memgraph memgraph/memgraph
This command will pull a MemgraphDB and run the container.
If you use our download page, then you need to load an image first with the following command:
docker load -i /path-to/memgraph-<version>-docker.tar.gz
After loading an image, you can build and run a container via the following command:
docker run -p 7687:7687 -p 7444:7444 -v mg_lib:/var/lib/memgraph memgraph/memgraph
If you want to install Memgraph platform (MemgraphDB, Lab, mgconsole, Mage), then only option is Docker hub, and running the following command:
docker run -it -p 7687:7687 -p 7444:7444 -p 3000:3000 -v mg_lib:/var/lib/memgraph memgraph/memgraph-platform
Previous command will pull the latest image, build the container and run it.
You can find a lot more information on MacOS installation docs
In addition, there are Linux native packages for Ubuntu, Debian and Centos 7,8.

How to install qemu emulator for arm in a docker container

My goal is to build a Docker Build image that can be used as a CI stage that's capable of building a multi-archtecture image.
FROM public.ecr.aws/docker/library/docker:20.10.11-dind
# Add the buildx plugin to Docker
COPY --from=docker/buildx-bin:0.7.1 /buildx /usr/libexec/docker/cli-plugins/docker-buildx
# Create a buildx image builder that we'll then use within this container to build our multi-architecture images
RUN docker buildx create --platform linux/amd64,linux/arm64 --name=my-builder --use
^ builds the container I need, but does not include the emulator of arm64. This means when I try to use it to build a multiarchitecture image via a command like docker buildx build --platform=$SUPPORTED_ARCHITECTURES --build-arg PHP_VERSION=8.0.1 -t my-repo:latest ., I get the error:
error: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c apt-get update && apt-get -y install -q ....
The solution is to run docker run --rm --privileged tonistiigi/binfmt --install arm64 as part of the CI steps, which uses the buildx container I previously built. However, I'd really like to understand why the emulator cannot seem to be installed in the container by adding something like this to the Dockerfile:
# Install arm emulator
COPY --from=tonistiigi/binfmt /usr/bin/binfmt /usr/bin/binfmt
RUN /usr/bin/binfmt --install arm64
I'd really like to understand why the emulator cannot seem to be installed in the container
Because when you perform a RUN command, the result is to capture the filesystem changes from that step, and save them to a new layer in your image. But the qemu setup command isn't really modifying the filesystem, it's modifying the host kernel, which is why it needs --privileged to run. You'll see evidence of those kernel changes in /proc/sys/fs/binfmt_misc/ on the host after configuring qemu. It's not possible to specify that flag as part of the container build, all steps run in the Dockerfile are unprivileged, without access to the host devices or the ability to alter the host kernel.
The standard practice in CI systems is to configure the host in advance, and then run the docker build. In GitHub Actions, that's done with the setup-qemu-action before running the build step.

Linking graphic card in Docker via OpenCL

I am on Ubuntu 19.10. and would like to use OpenCL inside docker.
Inside of the docker container I have installed opencl-headers,ocl-icd-opencl-dev and clinfo.
When I run clinfo on my machine outside of docker I have following response:
Number of platforms 1
Platform Name NVIDIA CUDA
Platform Vendor NVIDIA Corporation
Platform Version OpenCL 1.2 CUDA 10.2.159
...
When same is run in docker:
Number of platforms 0
I thought docker container should be able to use my graphic card, but am unsure if/how I should allow it.
Thank you for some insights
You need to start docker with the --gpus all option, eg:
docker run --rm --gpus all nvidia/opencl clinfo
You can also expose just a specific gpu:
docker run -it --rm --gpus "device=0" ubuntu nvidia-smi
Read more here: https://docs.docker.com/config/containers/resource_constraints/
If you get this error:
$ docker run --rm --gpus all nvidia/opencl clinfo
docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].
On Ubuntu, you can remedy it with:
$ sudo apt install -y nvidia-container-toolkit; sudo systemctl restart docker

docker build with nvidia runtime

I have a GPU application that does unit-testing during the image building stage.
With Docker 19.03, one can specify nvidia runtime with docker run --gpus all but I also need access to the gpus for docker build because I do unit-testing. How can I achieve this goal?
For older version of docker that use nvidia-docker2 it was not possible to specifiy runtime during build stage, BUT you can set the default runtime to be nvidia, and docker build works fine that way. Can I do that in Docker 19.03 that doesn't need nvidia-docker anymore? If so, how?
You need use nvidia-container-runtime as explained in docs: "It is also the only way to have GPU access during docker build".
Steps for Ubuntu:
Install nvidia-container-runtime:
sudo apt-get install nvidia-container-runtime
Edit/create the /etc/docker/daemon.json with content:
{
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime",
"runtimeArgs": []
}
},
"default-runtime": "nvidia"
}
Restart docker daemon:
sudo systemctl restart docker
Build your image (now GPU available during build):
docker build -t my_image_name:latest .
A "solution" I found is to first run a base image with the host nvidia drivers mounted on it
docker run -it --rm --gpus ubuntu
And then build my app within the container manually and commit the resulting image.
This is not ideal and it would be best to have access to nvidia-smi during the build phase.

How to run gui apps like gvim from docker container

To play around with a docker image, I installed docker and ran a sample docker ubuntu image as follows. (I hope I am using terminology correctly, still a docker noob)
docker run -it ubuntu
Because gvim or anyother gui based program was not installed, by default, I did, inside the ubuntu docker container
apt-get update
apt-get install x11-apps vim-gtk
However, on running xclock I get
root#59be2b1afca0:/# xclock
Error: Can't open display: :0
root#59be2b1afca0:/#
On running gvim I get
root#59be2b1afca0:/# gvim
E233: cannot open display
Press ENTER or type command to continue
So why won't gui apps work?
Containers weren't quite designed originally for gui apps, but rather for services, workers, processes, etc.. On the other hand since containerisation is a kernel construct to isolate and dedicate resources in a more managed way which can expose ports or share volumes, and devices etc..
This means you can technically map your screen, audio, webcam devices to a container by using --device /dev/xyz when you run your docker run command:
docker run [--rm [-it]|-d] \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY \
--device /dev/dri \
myimage [cmd]
I actually found an article describing this here - including audio, camera and other device mapping.
http://somatorio.org/en/post/running-gui-apps-with-docker/
Hope this helps a bit!

Resources