简体   繁体   中英

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

I've created a container of my netcore 2.2 console app. The main function must receive 2 arguments in order to start. If 2 arguments are not passed an exception will be thrown.

I'm running docker on windows.

This is my docker file:

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

This is my main function in the console app, yes nothing special but it needs two arguments ie in this case "BTCUSDT" and "1min"

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

I've tried running the image/container with the following command, but nothing:

docker start thirsty_bose "BTCUSDT" "1min"

I don't want to hardcode the arguments in the dockerfile, I want to pass them with docker start command. How can I make this work?

There are multiple ways of passing an argument. If you need to pass it at the build-time of image please use --build-arg VAR=VALUE

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

Or If you want to pass at run time, please use ENV and pass it when you run docker run command.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM