abr_78
abr_78

Reputation: 33

Run Python from Docker

I'm trying out Docker these days and I want to run create virtual environments in Python in Docker. I downloaded Miniconda3 from docker hub and tested out with basic hello world program written in python.

I ran:

docker run -i-t continuumio/miniconda3 /bin/bash

Then on another terminal I ran:

docker exec laughing_wing "python ~/Documents/Test/hello_world.py"

Where the name of docker container is laughing_wing, and my hello_world.py is in Documents/Test directory.

But running the second command I get:

"OCI runtime exec failed: exec failed: container_linux.go:344: starting container process caused "exec: \"python ~/Documents/Test/hello_world.py\": stat python ~/Documents/Test/hello_world.py: no such file or directory": unknown"

I'm confused about this.

Upvotes: 0

Views: 278

Answers (1)

Looks like you're trying to have the docker container run a python file from your machine. The docker container is isolated from it's host, so you need to either create your own Docker image where you add the file, or mount the ~/Documents/Test directory to your docker container. Something like this:

docker run -it -v ~/Documents/Test:/Test continuumio/miniconda3 /bin/bash

docker exec *container_name* "python /Test/hello_world.py"

Upvotes: 1

Related Questions