运行由 Docker 镜像提供的子程序在主脚本中。

huangapple go评论72阅读模式
英文:

Running a subroutine provided by a docker image within the main script

问题

The best practice for running a library provided by a Docker image in a Python program is to use Docker containers to isolate the library's environment. To use the library from https://github.com/oseledets/ttpy in your Python script:

  1. Pull the Docker image:

    docker pull oseledets/ttpy
    
  2. Create a Docker container from the image and run it:

    docker run -it oseledets/ttpy
    
  3. Inside the Docker container, you can use the ttpy library as needed.

To pass a tensor from your main Python script to the Dockerized ttpy library and perform operations on it, you would typically use some form of inter-process communication, such as sockets or RESTful APIs, to send data between your main script and the Docker container.

You don't necessarily need "Python on Whales" specifically for this task; regular Python scripts and Docker commands should suffice.

英文:

What is the best practice when wanting to run a library that is given by a docker image in a python program?

I'm trying to use the library: https://github.com/oseledets/ttpy , in one of my python scripts but it seems like installing it from pip is not working due to some fortran issue, one of the suggested fixes is using a docker image, the docker image works but how would I for example take a tensor in my main python script and perform a rounding operation on it using the docker version of the ttpy library?

Basically, do I use something like python on whales to call it from my main script and pass it a tensor?

Thanks.

答案1

得分: 1

A Docker container has an isolated filesystem. If some library is only installed in a container, you can't import it from a non-container process. Typically a Docker image will contain a complete application and not just a library.

在Docker容器中,有一个隔离的文件系统。如果某个库只安装在容器中,您无法从非容器进程中导入它。通常,Docker镜像将包含一个完整的应用程序,而不仅仅是一个库。

In the particular GitHub repository you link to, the Docker image appears to principally provide a Python REPL for experimentation. The Dockerfile is in the repository, and you can see what it does: it starts FROM python:3.10, installs some dependencies, and installs the ttpy library from the local sources, but it doesn't itself contain a CMD.

在您提供的特定GitHub存储库中,Docker镜像似乎主要提供了一个用于实验的Python REPL。Dockerfile在存储库中,您可以看到它的内容:它以FROM python:3.10为基础,安装了一些依赖项,并从本地源安装了ttpy库,但它本身不包含CMD指令。

If this is a reasonable base for your application and you can use exactly the Python version this image packages then you could build an image FROM daskol/ttpy, but it might be more maintainable to repeat the installation steps from that Dockerfile in your own image.

如果这对于您的应用程序是一个合理的基础,并且您可以使用此镜像打包的确切Python版本,那么您可以构建一个镜像FROM daskol/ttpy,但在您自己的镜像中重复Dockerfile中的安装步骤可能更易于维护。

英文:

A Docker container has an isolated filesystem. If some library is only installed in a container, you can't import it from a non-container process. Typically a Docker image will contain a complete application and not just a library.

In the particular GitHub repository you link to, the Docker image appears to principally provide a Python REPL for experimentation. The Dockerfile is in the repository, and you can see what it does: it starts FROM python:3.10, installs some dependencies, and installs the ttpy library from the local sources, but it doesn't itself contain a CMD.

If this is a reasonable base for your application and you can use exactly the Python version this image packages then you could build an image FROM daskol/ttpy, but it might be more maintainable to repeat the installation steps from that Dockerfile in your own image.

huangapple
  • 本文由 发表于 2023年5月30日 00:37:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76358984.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定