我正在Visual Studio中玩docker。我有一个在docker中运行的控制台应用程序,我想与之通信。
docker-compose.yml和Dockerfile是标准的,由VS生成
docker-compose.yml:
version: '3.4'
services:
publisher:
image: ${DOCKER_REGISTRY-}publisher
build:
context: .
dockerfile: Publisher/Dockerfile
发布者/ Dockerfile:
FROM microsoft/dotnet:2.2-runtime AS base
WORKDIR /app
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY Publisher/Publisher.csproj Publisher/
RUN dotnet restore Publisher/Publisher.csproj
COPY . .
WORKDIR /src/Publisher
RUN dotnet build Publisher.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Publisher.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Publisher.dll"]
发布者:
namespace Publisher
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World, I'm a publisher!");
while(true)
{
var line = Console.ReadLine();
if (line == null)
{
break;
}
Console.WriteLine(line.ToUpper());
}
}
}
}
我想写给发布者应用程序标准输入。运行docker attach my_publisher
,控制台根本不接受我的输入。从容器中分离出来后,上面提到的输入将输入到控制台。
我尝试更改docker-compose.yml:
version: '3.4'
services:
publisher:
image: ${DOCKER_REGISTRY-}publisher
build:
context: .
dockerfile: Publisher/Dockerfile
stdin_open: true # HERE
tty: true # AND HERE
现在似乎可以接受我的输入了(分离后我的控制台上没有输入它),但是我看不到任何输出,所以我不确定。
那么我应该怎么做才能在应用程序中输入输入并读取输出?