Integration tests with docker compose

I have a simple dotnet test that just fails during running:

        [Fact]
        public void Test1()
        {
            throw new System.Exception("test");
        }

that I want to launch via docker-compose.
NOTE: It’s a synthetic case that just asks about proper configuration to run custom script (bash/cmd?) from docker-compose side. In real example I want to add an integration test that will include communicating logic with different containers as in my main application.

Docker file:

        FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
        WORKDIR /src
        EXPOSE 80
        EXPOSE 443
        # restore
        COPY ["MyTests/MyTests.csproj", "MyTests/"]
        RUN dotnet restore "MyTests/MyTests.csproj"
        # build
        COPY . .
        WORKDIR "/src/MyTests"
        RUN dotnet build "MyTests.csproj" -c Release -o /app/build

        ENTRYPOINT ["/bin/bash"]

. This files configuration works well, when I run this from my local machine:

        %SomePath%\Demo>docker build -f MyTests/Dockerfile  -t mytest .
        [+] Building 0.3s (12/12) FINISHED
         => [internal] load build definition from Dockerfile
         => => transferring dockerfile: 32B
         => [internal] load .dockerignore
         => => transferring context: 35B
         => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0
         => [1/7] FROM mcr.microsoft.com/dotnet/sdk:6.0
         => [internal] load build context
         => => transferring context: 2.00kB
         => CACHED [2/7] WORKDIR /src 
         => CACHED [3/7] COPY [MyTests/MyTests.csproj, MyTests/] 
         => CACHED [4/7] RUN dotnet restore "MyTests/MyTests.csproj"
         => CACHED [5/7] COPY . .
         => CACHED [6/7] WORKDIR /src/MyTests
         => CACHED [7/7] RUN dotnet build "MyTests.csproj" -c Release -o /app/build
         => exporting to image
         => => exporting layers
         => => writing image sha256:9c...
         => => naming to docker.io/library/mytest

        %SomePath%\Demo>docker run -it mytest
        root@999afef78716:/src/MyTests# ls
        MyTests.csproj  ApiTests.cs  Properties  obj

You may see, that now I’m able to use bash scripts, so I “can” run something like: “dotnet test” to launch tests I have.
But when I do similar steps via docker-compose:

        version: '3.4'

        services:
          xunitwithdocker:
            image: ${DOCKER_REGISTRY-}xunitwithdocker
            build:
              context: .
              dockerfile: XUnitWithDocker/Dockerfile
            command: ["echo", "test!"]

The container throws:

==> /dev/null <==
tail: cannot open 'echo' for reading: No such file or directory
tail: cannot open 'test!' for reading: No such file or directory

It’s a bit unclear where “tail” has come from?
My colleague has created a SO question about it here: bash - Docker Compose. Call a custom script - Stack Overflow

Can someone help with this?

It appears to be from the images entrypoint script. Share your Dockerfile and we will see that the ENTRYPOINT instruction either uses tail or points to a script that does use tail and then hands over to $@

I already did this, see above.

Indeed, you shared it. I missed it.

I would have expected to see an entrypoint script or tail itself.

You might want to change your ENTRYPOINT to ["/bin/bash","-c"].
Though, it remains a mystery why the tail command was involved at all.

still the same, I can share a small repro project if it would work

Apparently the tail part is added by visual studio that I used to build and run my application, I found it in the logs:

    docker-compose  -f "%PATH%\docker-compose.yml" -f "%PATH%\docker-compose.override.yml" -f "%PATH%\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose14997374556887134345 --ansi never --profile "*" config
    name: dockercompose14997374556887134345
    services:
      consoleappdocker:
        build:
          context: %PATH%
          dockerfile: ConsoleAppDocker/Dockerfile
          labels:
            com.microsoft.created-by: visual-studio
            com.microsoft.visual-studio.project-name: ConsoleAppDocker
        command:
        - /bin/bash
        - -c
        - echo test
        container_name: consoletest
        entrypoint:
        - tail
        - -f
        - /dev/null
        environment:
    ..
        image: consoleappdocker:dev
        labels:
    ..
        networks:
          default: null
        tty: true
        volumes:
    ..
    networks:
      default:
        name: dockercompose14997374556887134345_default
    docker-compose  -f "%PATH%\docker-compose.yml" -f "%PATH%\docker-compose.override.yml" -f "%PATH%\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose14997374556887134345 --ansi never build

quite unexpected case, now I’m thinking about how can I disable this…