CoderMJ
CoderMJ

Reputation: 17

How to run a python file which is present outside the docker container

Inside VM I created a docker container, Now there are some python files present outside the container(present in host directory of VM) how can I execute these python files from container anyone help me with this

Upvotes: 1

Views: 1491

Answers (3)

CoderMJ
CoderMJ

Reputation: 17

docker run -t -i -v <host_dir>:<container_dir> ubuntu /bin/bash By this command I'm able to access host directory by inside the container where the directories are mounted and can able to run python file present in host by container

Upvotes: 0

Sharique Masood
Sharique Masood

Reputation: 174

you can copy or mount the python file inside the docker container then execute the python with CMD.

For ex: docker run -it -v myfile.py:/tmp/myfile.py python python /tmp/myfile.py

Upvotes: 0

Rub&#233;n Pozo
Rub&#233;n Pozo

Reputation: 1083

You should mount the vm directory like this:

docker run -d -it --name your-container-name -v /host/path:/usr/local/bin container:image

Also you must be sure /host/path permissions are propperly set. Volumes in docker

Upvotes: 2

Related Questions