运行 dot net core console 图像时如何在启动时将参数传递给 docker 容器

How to pass arguments to a docker container at start when running an image of dot net core console

我已经为我的 netcore 2.2 控制台应用程序创建了一个容器。 主函数必须接收 2 个参数才能启动。 如果未传递 2 个参数,将抛出异常。

我 运行 docker windows。

这是我的 docker 文件:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
COPY bin/Release/netcoreapp2.2/publish/ app/
ENTRYPOINT ["dotnet", "app/BinanceLoggerCandleStick.dll"]

这是我在控制台应用程序中的主要功能,是的,没什么特别的,但它需要两个参数 即在这种情况下 "BTCUSDT" 和“1min”

static void Main(string[] args)
{
//some code
}

我已经尝试使用以下命令 运行 image/container,但没有成功:

docker start thirsty_bose "BTCUSDT" "1min"

我不想硬编码 docker 文件中的参数,我想用 docker 启动命令传递它们。 我怎样才能使这项工作?

有多种传递参数的方法。如果您需要在图像构建时传递它,请使用 --build-arg VAR=VALUE

Reference:- https://docs.docker.com/engine/reference/builder/#arg

或者如果你想在运行的时候传,请用ENV在你运行docker run命令的时候传。

Reference:- https://docs.docker.com/engine/reference/builder/#env