Docker - 多个基础镜像?在单个图像中使用 Python 的 NetCore 运行时 [英] Docker - multiple base images? NetCore runtime with Python in single image

查看:18
本文介绍了Docker - 多个基础镜像?在单个图像中使用 Python 的 NetCore 运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台 .Net Core 应用程序,它也使用 Python、nVidia CUDA 运行时等.

I have a console .Net Core application which also uses Python, nVidia CUDA runtime, etc.

我知道构建模式,但到目前为止我只是直接使用 Visual Studio 的构建输出来创建图像,所以我的 Dockerfile 很简单:

I know about building patterns, but so far I just directly use build output of Visual Studio to create image, so my Dockerfile is simple:

FROM mcr.microsoft.com/dotnet/core/runtime:3.1.4-buster-slim AS base
FROM base AS final
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "MyApp.dll"]

与使用 NetCore 运行时的方式相同,有 Python 和 nVidia CUDA 图像可用.但是如果我只是用 Python 运行另一个容器 - 我的应用程序无法从这个容器使用 Python,因为容器是隔离的,它们可能只能使用 TCP 进行交互.我的想法是我可能会使用多个图像作为我的应用程序图像的基本图像,但我没有看到使用多个 FROM 语句来组合来自它们的单个图像的方法.

In the same way as with the NetCore runtime, there're Python and nVidia CUDA images available. But if I just run another container with Python - my app is unable to use Python from this container, because containers are isolated and they may only interact using TCP. My thought was that I might use multiple images as base image for image with my app, but I don't see a way to use multiple FROM statements to combine one single image from them.

将 Python、CUDA 和其他图像与容器中的环境与我正在运行的应用程序一起使用的正确方法是什么,默认情况下只有 NetCore 运行时?

What's the proper way of using Python, CUDA and other images with environments from container with my running app, which only has NetCore runtime by default?

推荐答案

如果没有包含你想要的一切的容器镜像,你可以编写自己的容器镜像来构建这样的东西.

In the case where there's no container image that includes everything you want, you can write your own container image to build such a thing.

FROM mcr.microsoft.com/dotnet/core/runtime:3.1.4-buster-slim AS base

这个容器基于 Debian buster.这是一个带有 Python 的 Linux 发行版.据我所知,它可能没有 CUDA,因为 Debian 是关于自由的,而 CUDA 是非自由的.

This container is based on Debian buster. That's a Linux distribution that has Python. It probably doesn't have CUDA, since Debian's all about Freedom and CUDA is non-free, to the best of my knowledge.

在这种情况下,您可以做两件事:

In this case, you can do 2 things:

  1. 使用包管理器安装发行版中可用的语言/库

  1. Install languages/libraries you need that are available in the distribution using the package manager

手动安装通过包管理器不可用的东西.

Manually install things that are not available via the package manger.

所以你可能想要这样的东西:

So you probably want something like this:

FROM mcr.microsoft.com/dotnet/core/runtime:3.1.4-buster-slim AS base
RUN apt-get install -y python3
RUN wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/cluster_management/cuda_cluster_pkgs_10.2.89_440.33.01_ubuntu1804.tar.gz
RUN true # extract/install the tar file from above, I dont use CUDA so I dont know
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "MyApp.dll"]

此 dockerfile 以包含 .NET Core 的容器映像开始.然后它在其中安装python.然后它会在其中安装 CUDA.然后它运行您的应用程序.

This dockerfile starts with a container image that include .NET Core. Then it installs python in it. Then it installs CUDA in it. Then it runs your application.

这篇关于Docker - 多个基础镜像?在单个图像中使用 Python 的 NetCore 运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆