How to run a tkinter file on Docker in Windows? - docker

I am trying to run a GUI created using tkinter on Docker.
This is the docker run command:
docker run -u=$(id -u $USER):$(id -g $USER) -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw -v $(pwd)/app:/app --rm tkinter_in_docker
I am getting the error:
unknown shorthand flag: 'g' in -g
See 'docker run --help'.
What is the correct way to run to get the desired results?

Related

Docker cant find file location in windows 10

I am trying to run a software for predicting hemorrhage volume on brain CT in docker: https://github.com/msharrock/deepbleed
I created a "deepbleed" folder in my D:\ drive on windows, and ran docker pull msharrock/deepbleed command after I cd'd inside that directory. The pull was successful and I can see the container in my docker desktop app.
Then I went on and created an indir and outdir folder as instructed in documentation; placed my CT file for prediction in the indir folder.
The readme tells me to run this command next:
docker run -it msharrock/deepbleed bash -v /path/to/data:/data/
So I have run the following commands, but I get "no such file or directory" for all of them:
docker run --rm -it msharrock/deepbleed bash -v pwd/deepbleed/indir:outdir
docker run --rm -it msharrock/deepbleed bash -v ~/deepbleed/indir:/outdir/
docker run --rm -it msharrock/deepbleed bash -v /mnt/d/deepbleed/indir:/outdir/
docker run --rm -it msharrock/deepbleed bash -v /d/deepbleed/indir:/outdir
docker run --rm -it msharrock/deepbleed bash -v "$(& "D:\deepbleed\indir" "$(pwd)")":/outdir
docker run --rm -it msharrock/deepbleed bash -v /indir/:/outdir/
docker run --rm -it msharrock/deepbleed bash -v //d:/deepbleed/indir://d:/deepbleed/outdir/
docker run --rm -it msharrock/deepbleed bash -v //d/deepbleed/indir://d/deepbleed/outdir/
docker run --rm -it msharrock/deepbleed bash -v //d/deepbleed/indir:/outdir/
My docker is running on a wsl2 based engine in windows 10, the hyper-v folders for disks and virtual machines are located on my d: drive.
What do I need to do to get this running?
Try doing it like this (just using one of your items in the list for this example to give you the idea):
docker run -rm -it -v /mnt/d/deepbleed/indir:/outdir msharrock/deepbleed bash

Docker: standard_init_linux.go:211

I try to run python script with docker on windows pro in PowerShell.
When I run:
docker run -it --name mypython -v ${PWD}/myfirst:/app python /app/myfirst.py
I am getting an error:
standard_init_linux.go:211: exec user process caused "exec format error"
myfirst.py includes only a print statement:
print('Python in Containers!')
In same time, the following pieces of code work fine:
docker run -it --name mypython -v ${PWD}/myfirst:/app python
>>> exec(open('/app/myfirst.py').read())
Python in Containers!
and
docker run -it --name mypython -v ${PWD}/myfirst:/app python /bin/bash
root#fc18bbcfb818 cd /app
root#fc18bbcfb818 python myfirst.py
Python in Containers!
Any ideas why this happens?
The python Docker image has the CMD python3. This means that if you provide arguments after the image name, the CMD will be overwritten. So OP's example is equivalent to running /app/myfirst.py on the command line (note how this is different from python /app/myfirst.py). To fix this, use python /app/myfirst.py.
docker run -it --name mypython -v ${PWD}/myfirst:/app python python /app/myfirst.py

How to run commands in Docker container

Hello I m trying to follow the step by step guid to build jpeg xl (I m on windows and try to build a x64 version for linux)
after:
docker run -u root:root -it --rm -v C:\Users\fred\source\tools\jpegxl\jpeg-xl-master -w /jpeg-xl gcr.io/jpegxl/jpegxl-builder
I have the container running but I don't know how to run the command inside :
CC=clang-6.0 CXX=clang++-6.0 ./ci.sh opt
I tried CC=clang-6.0 CXX=clang++-6.0 ./ci.sh opt and I get ./ci.sh: No such file or directory no command seems to work when I do "ls" it display nothing
Does someone knows how to get this to build?
Make sure that you start a bash terminal inside the container:
docker run -it <image> /bin/bash
I believe /bin/bash is missing from your docker run command. As a result, you are executing the command for clang inside your own environment, not the container.
You can set the environment variables by using -e
Example
-e CC=clang-6.0 -e CXX=clang++-6.0
The full command to log in into your container:
docker run -u root:root -it --rm -e CC=clang-6.0 -e CXX=clang++-6.0 -v C:\Users\fred\source\tools\jpegxl\jpeg-xl-master -w /jpeg-xl gcr.io/jpegxl/jpegxl-builder /bin/bash
They have updated the image without updating the command so the command is
CC=clang-7 CXX=clang++-7 ./ci.sh opt
The discution is here:
Can't build from docker image "Unknown clang version"

Docker cannot connect to X server

I have created a docker image for opencv and facial reckognition to simplify the setup process.
But the recognize.py script needs X Server to show the image result. Here is what I have done so far:
sudo docker run -t -d --name opencv opencv:latest
sudo docker exec -it opencv bash /extract-embeddings.sh
sudo docker exec -it opencv bash /train-model.sh
All is fine so far. The last step is the actual comparison that displays the result in an image.
sudo docker exec -it opencv bash /face-recognition.sh
It gives the output:
[INFO] loading face detector...
[INFO] loading face recognizer...
No protocol specified
: cannot connect to X server :0
I have tried running the container with the following command:
sudo docker run -t -d --name opencv -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix opencv:latest
But it doesn't help.
Try running this,
xhost +
sudo docker run --rm -ti --net=host --ipc=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --env="QT_X11_NO_MITSHM=1" <image_name> <arguments>
Other might face issue regarding the image not getting rendered on screen or getting a blank screen with no image, for them add --env="_X11_NO_MITSHM=1" to the above script while running the docker image. It will solve the problem.
For further information, I would recommend you guys check out the below references.
Reference 1
Reference 2
It looks like the xauth is the issue for viewing of the image.
The details are at Can you run GUI applications in a Docker container?
It may happen that also the XAuthority is needed.
First, make sure that the host's $XAUTHORITY is defined.
And second, add the following parameters to the docker run command:
-v $XAUTHORITY:/tmp/.XAuthority -e XAUTHORITY=/tmp/.XAuthority
An example of a complete command:
sudo docker run --rm -ti --net=host --ipc=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $XAUTHORITY:/tmp/.XAuthority -e XAUTHORITY=/tmp/.XAuthority --env="QT_X11_NO_MITSHM=1" <image_name> <arguments>

How to escape colon when add device to docker container?

This is ok to add device which by serial id:
docker run -it --rm --device /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A101A9A7-if00-port0 -v /dev:/dev ubuntu /bin/bash
This is not ok to add device which by serial path:
docker run -it --rm --device /dev/serial/by-path/pci-0000:00:14.0-usb-0:8:1.0-port0 -v /dev:/dev ubuntu /bin/bash
It reports error:
invalid argument "/dev/serial/by-path/pci-0000:00:14.0-usb-0:8:1.0-port0" for "--device" flag: bad format for path: /dev/serial/by-path/pci-0000:00:14.0-usb-0:8:1.0-port0
See 'docker run --help'.
Same error if do escape string for : as next:
docker run -it --rm --device /dev/serial/by-path/pci-0000\:00\:14.0-usb-0\:8\:1.0-port0 -v /dev:/dev ubuntu /bin/bash
As I know, for bind mount, we now could use something like --mount type=bind,source=/colon:path/test,destination=/data to handle it, see this.
So my question is: for --device, what could I do?
Answer for myself, from this discussion:
It seems CLI not support escaping the colons, currently the only way is to make symbol link like next:
ln -s /dev/serial/by-path/pci-0000:00:14.0-usb-0:8:1.0-port0 /dev/serial/by-path/mydevice01
docker run -it --rm --device /dev/serial/by-path/mydevice01 -v /dev:/dev ubuntu /bin/bash
This is what I made workaround currently.

Resources