Videos
I'm not sure what you are trying to do. But here are some tips, that may help you.
- Python libraries for working with docker from python
- https://github.com/docker/docker-py
- https://github.com/deepgram/sidomo
- You can start container's python console
docker run -ti myimage python - Also you can have connected
volumeswhere you will store your source code and than run this code with container's environment
NEW 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} ...
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.
You're practically renaming your package (it smells like a package, having __init__.py and __main__.py) from "src" to "vdp" when you're creating the dockerfile.
I'd recommend:
- Rename
src/...tosrc/vdp/...(orvdp/...) – at this point you should be able to runpython -m vdpwithin thesrcdirectory on your host machine and things should work. - Change the Dockerfile stanzas to
COPY src /src
WORKDIR /src
ENTRYPOINT ["python3", "-m", "vdp"]
– this'd be equivalent to how you're running it on the host machine.
Another option would be to drop the /src in the repository and change things to COPY vdp /src/vdp.
The third option, of course, would be to set up proper Python packaging, have your setup.py build a proper wheel, then simply install that in the Docker container.
Python is not able to find the file base_functions because it was run from other folder.
You may want to change the working directory of in the Dockerfile:
WORKDIR /path/to/workdir