Reputation: 3956
I made a docker image contains nginx, uwsgi and some python module, using volumes out the docker to develop code.
So how should I use python environment from docker when coding?
Upvotes: 1
Views: 5731
Reputation: 906
Not sure if this is what you're asking but if you have Python libraries within the Docker image and you want to append them to an already-exisitng Pipfile
, you can copy the requirements.txt
file from the Docker container and then use pipenv
to install them.
# In terminal session 1 run the container with the default shell in interactive mode. This way the container stays alive and we can copy the file from the container to the host
docker run -it --rm $USER/$IMAGE_NAME:1.0.0.XXXXX sh
# In terminal session 2
docker cp $CONTAINER_ID:/requirements.txt ./
# This will add the requirements from the text file into the Pipfile
pipenv install -r requirement.txt
# Sometimes requirements will get corrupted
pipenv clean
If using Visual Studio Code, reload window to refresh dependencies in Python interpreter.
Upvotes: 0
Reputation: 15360
I'm not sure what you are trying to do. But here are some tips, that may help you.
docker run -ti myimage python
volumes
where you will store your source code and than run this code with container's environmentNEW IDEA
Importing module in python means having module's folder in your PYTHONPATH
. So basically you probably would need to mount your docker with something like sshfs
to some folder, and than add this folder to your PYTHONPATH
. After that you can do from {docker_module} ...
Upvotes: 1