我正在使用docker-compose:
version: "3"
services:
app:
build:
context: .
dockerfile: Dockerfile
和dockerfile:
FROM microsoft/dotnet:2.2-sdk
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# copy and build everything else
COPY . ./
RUN dotnet publish -c Release -o out
ENTRYPOINT ["dotnet", "out/testapp.dll"]
我的问题是,如何使用docker-compose up命令将参数传递给docker-compose和dockerfile?
解决方案:
我使用此代码“ variable = value docker-compose up”将变量发送到docker-compose,并将此代码添加到docker-compose文件中
environment:
- variable=${variable}
并在Dockerfile中以这种格式使用入口点:
ENTRYPOINT dotnet "testapp.dll" "$variable"
答案 0 :(得分:0)
您似乎想使用environment variables。声明一个环境变量(例如这里的DLL
):
version: "3"
services:
app:
build:
context: .
dockerfile: Dockerfile
environment:
- DLL=out/testapp.dll
然后在Dockerfile
中将其用作环境变量(最后一行):
FROM microsoft/dotnet:2.2-sdk
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# copy and build everything else
COPY . ./
RUN dotnet publish -c Release -o out
ENTRYPOINT dotnet "$DLL"