execute python script using docker - python

I have a problem with docker. I have a docker image
docker images
and I want to execute a simple python script on the kakadadroid/python27-talib image. The script is located in /home/Elise/technical_indicator.py.
but when I try:
docker run --volume=$(pwd):/workspace kakadadroid/python27-talib:latest python home/Elise/technical_indicator
I have the following error:
python: can't open file 'home/Elise/technical_indicator.py': [Errno 2] No such file or directory
Can someone help me. I'm not an expert in docker.
Kind regards
Emmanuel

If you see your command line docker run --volume=$(pwd):/workspace kakadadroid/python27-talib:latest python home/Elise/technical_indicator it could have many causes. Try the following:
Your file path it's not correct. It should be /home/Elise/technical_indicator.py instead of home/Elise/technical_indicator.py. You've forgotten the / at the start of path specification.
The volume does not exist.
If the volume exists, the solution would be:
docker run --volume=$(pwd):/workspace kakadadroid/python27-talib:latest python /home/Elise/technical_indicator
Note: You should add your Dockerfile to let us understand better your problem.
Regards :)

Related

Python raspberry pi Ubuntu System FileNotFound Error on terminal but it works on Code-server with another Path

Somethimes it works and somethimes it does not work. I want to run my script from terminal but i always get FileNotFound Error. I only use Absolute Path. FileNotFoundError: [Errno 2] No such file or directory: '/umbrel/umbrel/app-data/code-server/data/resourcen/duplicates.xlsx' This path also works not on Code Server. But this works on code-server envirement with this but not on command line path = r"/home/coder/DaxBull/". But i need to run it on terminal because i want to run a cronjob. You can ask If you have any questions. I would be verry greatfull if somebody could help i try to fix it sice 2 days. Thank you

Python script does not create files in Docker container when run from a batch file

I have a Python script which needs to be run inside a Docker container (because that's how a piece of software needed is installed). This script creates some files that are needed for later processing.
When I run in the Command Prompt
docker exec -it CONTAINER bash
python3 script.py
the script does generate the files. However, I tried to use a batch file to automate the process:
docker exec -it CONTAINER python3 script.py
The script does run, since it prints information in the Command Prompt, but it does not create the files I need. What am I doing wrong?
So thanks to the comments from ghatzhat and Mofi I figured the issue: the script was saving files in the root folder in the container. This was because I hadn't specified the file path in script.py.
Since I'd like the files to be in the same folder as the script no matter where it is, and changing the path inside the script would take some work, I instead changed the working directory in the batch file by using
docker exec -w FOLDER_SCRIPT CONTAINER python3 script.py
where FOLDER_SCRIPT is where the script is located.
Honestly, it seems obvious in hindsight, but guess that's part of learning curve. Thanks again to ghatzhat and Mofi for their helpful comments!

Dockerfile not being found for Google cloud run

I've hit another bug. I'm now trying to set up continuous deployment for Google Cloud Run from my GitHub, and it's not finding my Dockerfile. I've tried various combinations with my file paths, but it still gives me the
Already have image (with digest): gcr.io/cloud-builders/docker
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /workspace/Dockerfile: no such file or directory
error.
This is my file structure from VSCode, and if I run the command from the first Exeplore folder, it finds the Dockerfile
The source directory is public, so I just can't figure out why it's not finding the Dockerfile.
https://github.com/Pierre-siddall/exeplore
Any advice at all would be greatly appreciated, thank you!
EDIT 1:
For some reason, the file path had some capitalisation that was different than what was on my VSCode - I suspect something on Github's end. Now I'm having issues getting the continuous deployment to actually update the page, but it is redeploying, but not updating now.

Python File Directory Can't be found

When I try to run my python file, I get the following error: "can't open file 'hello.py': [Errno 2] No such file or directory" I have tried cd and it shows that my file is in the Users/ierdna/ directory. I have the python program on my desktop and I still cannot run it.
Thanks very much!
It seems that I have tried everything, and nothing is working. :(
I am going to assume you know some of the basic BASH command line commands. If you don't check them out here.
Opening your terminal's respective shell, enter the following on your command line:
cd Desktop [to change directory to your desktop]
ls [to list all the directories and files on your desktop, to make sure your hello.py file is in fact there]
python hello.py [to run your python file]
That should run it. Let me know if you run into errors.
In order to properly answer this question the following information are required:
a. OS that you are using
b. Release version of that OS
c. Python version that you are using
d. If your machine has at least 10GB of free space
Kidding!
You just need to use cd ~/Desktop to make the 'Desktop' your working directory and then try to run python hello.py Alternatively you can also try running python ~/Desktop/hello.py directly without using 'cd' command. Note: In order to run a python script you need to provide the path(Either complete path, for example: python /home/username/Desktop/script.py or relative path, for example: python ../script.py) to the script. If you just provide the script name, it will fail unless the script exists in the current working directory. Also, kindly do check for existing questions and answers before posting your own question as I doubt this question is new and hasn't been answered correctly before.
I'm going to assume from you saying you used cd that you are using Mac or Linux. This solution will work for both. If I am wrong and you are running Windows, just comment it and I'll change the answer. On to the real answer:
First open your terminal, then type cd ~/Desktop. Now try running your python script.
EDIT:
Apparently you are running Windows. OK. I'm going to leave the above answer for other people who have the same problem on Mac or Linux. What you need to do is execute this command in your command prompt cd C:\Users\[your user name]\Desktop. Replace [your user name] with your actual user name. Then run your python script (python hello.py)

Error adding local file to docker image with docker-py

I have been working with docker-py, in order to build images and launch containers all in one script. So far it has been very smooth. However, I am currently having issues with the ADD/COPY commands in the Dockerfile string variable.
I need to add a file from the source directory directly into the image. With standard Dockerfiles, I have been able to achieve this successfully, using the docker ADD command. But using docker-py, it throws the exception:
Exception: Error building docker image: lstat simrun.py: no such file or directory
The script simrun.py is stored in the same directory as the docker-py script, so I cannot understand why I would be receiving this exception. The relative line in dockerpy.py is:
ADD ./simrun.py /opt
Is there something that I've missed, or will this functionality just not work in docker-py yet?
You need to set the path in the docker build context using the path parameter.
See here

Categories