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
Related
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?
I am following a tutorial series on yt https://www.youtube.com/watch?v=FkrpUaGThTQ
how to make an os soo
when in **Build for x86 ** use the command make build-x86_64 then it shows this error `
make: *** No rule to make target 'build-x86_64'. Stop.
`
I dont know how to fix it
Per the original YouTube author of the tutorial, this is the fix :
Try one of the following commands when entering the docker container from your host OS
For Linux, MacOS, WSL, etc :
docker run --rm -it -v "$pwd":/root/env myos-buildenv
docker run --rm -it -v "$PWD":/root/env myos-buildenv
docker run --rm -it -v "$(pwd)":/root/env myos-buildenv
Windows Powershell :
docker run --rm -it -v "${pwd}:/root/env" myos-buildenv
Windows CMD :
docker run --rm -it -v "%cd%":/root/env myos-buildenv
You just need to go back one directory by typing
"cd .."
then enter another command
"cd env" to move into the env folder
then you can enter "make build x86_64" command
Make the "MakeFile" file name as "makefile" and run the command "make build-x86_64"
Same problem I had. Just go on with Carey S.Turner`s answer.
Windows Powershell: docker run --rm -it -v "${pwd}:/root/env" myos-buildenv
Windows CMD: docker run --rm -it -v "%cd%":/root/env myos-buildenv
I had error with cmd but powershell worked fine for me.
I had the same error I found that it could be fixed by doing this bit right
Enter build environment:
Linux or MacOS: docker run --rm -it -v "$(pwd)":/root/env myos-buildenv
Windows (CMD): docker run --rm -it -v "%cd%":/root/env myos-buildenv
Windows (PowerShell): docker run --rm -it -v
"${pwd}:/root/env" myos-buildenv
Please use the linux command if you are using WSL, msys2 or git bash NOTE: If you are having trouble with an unshared drive, ensure your docker daemon has access to the drive you're development environment is in. For Docker Desktop, this is in "Settings > Shared Drives" or "Settings > Resources > File Sharing".
(https://github.com/davidcallanan/os-series/blob/ep1/README.md)
My error came out of me not doing the "$(pwd)" bit correctly
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"
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>
I've used docker run -it to launch containers interactively and docker run -d to start them in background. These two options seemed exclusive. However, now I've noticed that docker run -dit (or docker run -itd) is quite common. So what is the difference? When -it is really needed together with -d?
Yes, sometimes, it's necessary to include -it even you -d
When the ENTRYPOINT is bash or sh
docker run -d ubuntu:14.04 will immediately stop, cause bash can't find any pseudo terminal to be allocated. You have to specify -it so that bash or sh can be allocated to a pseudo terminal.
docker run -dit ubuntu:14.04
If you want to use nano or vim with any container in the future, you have to specify -it when the image starts. Otherwise you'll get error. For example,
docker run --name mongodb -d mongo
docker exec -it mongodb bash
apt-get update
apt-get install nano
nano somefile
It will throw an error
Error opening terminal: unknown.