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?