I'm playing around with docker in Visual Studio. I have a console app which runs in docker and I'd like to communicate with it.
docker-compose.yml and Dockerfile are standard ones, generated by VS
docker-compose.yml:
version: '3.4'
services:
publisher:
image: ${DOCKER_REGISTRY-}publisher
build:
context: .
dockerfile: Publisher/Dockerfile
Publisher/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"]
Publisher:
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());
}
}
}
}
I want to write to publisher app standard input. Running docker attach my_publisher, the console isn't accepting my input at all. After I detach from the container the input mentioned above is typed to my console.
I tried changing my 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
Now it seems to accept my input (it doesn't get typed to my console after I detach), but I see no output, so I'm not sure.
So what should I do to be able to type input to my app as well as read output?