<p>Teamcity agent is totally unable to detect it is running in docker and try to mount its own directories instead of the proper volumes into the launched container for the step (observed from a problem I encountered with a command line step to run a script within a docker environment).</p>
<p>You need to use command line step and do something like this (untested with .Net but should give the idea, you may need to install jq into the agent container too):</p>
<pre><code>MOUNTS=$( docker inspect teamcityagent | jq '.[0].Mounts[] | select(.Destination | contains(&quot;/opt/buildagent/&quot;)) | &quot;-v \(.Name):\(.Destination)&quot; ' -r | tr '\n' ' ')
docker pull mcr.microsoft.com/dotnet/sdk:5.0
docker run --rm $MOUNTS -w %teamcity.build.workingDir% mcr.microsoft.com/dotnet/sdk:5.0 /usr/bin/dotnet test %teamcity.build.workingDir%/ImPresent.Tests/ImPresent.Tests.csproj
</code></pre>

CC BY-SA 4.0
2023-04-07T14:49:33.140Z
2023-04-07T14:49:33.140Z
Tensibai
<p>Two things I would try:</p>
<ol>
<li><p>Add &quot;Build&quot; Step before testing:</p>
<p>Runner Type: <code>.NET</code>.</p>
<p>Command: <code>build</code>.</p>
<p>Also it may be required to add another build configuration to <code>Restore</code> the project before build.</p>
</li>
<li><p>Execute this build step in &quot;verbose&quot; mode to get more logging information.</p>
</li>
</ol>

CC BY-SA 4.0
2022-11-07T09:29:52.637Z
2022-11-07T09:29:52.637Z
Oliver A
<p>I'm trying to set up TeamCity to run tests on a .NET project. I have installed TeamCity and its agent (with access to docker) using docker compose :</p>
<pre class="lang-yaml prettyprint-override"><code>  teamcity:
    image: jetbrains/teamcity-server
    container_name: teamcity
    volumes:
     - /home/arsene/teamcity/data:/data/teamcity_server/datadir
     - /home/arsene/teamcity/logs:/opt/teamcity/logs
    environment:
      - TEAMCITY_HTTPS_PROXY_ENABLED=true
    labels:
      - traefik.http.routers.teamcity.rule=Host(`myhost`)
      - traefik.http.routers.teamcity.tls=true
      - traefik.http.routers.teamcity.tls.certresolver=le   
      - traefik.http.services.teamcity.loadbalancer.server.port=8111

  teamcityagent:
    image: jetbrains/teamcity-agent
    container_name: teamcityagent
    volumes:
     - /home/arsene/teamcity/agent:/data/teamcity_agent/conf
     - /var/run/docker.sock:/var/run/docker.sock
     - /opt/buildagent/work:/opt/buildagent/work
     - /opt/buildagent/temp:/opt/buildagent/temp
    environment:
      - AGENT_NAME=TeamCityRunner
      - SERVER_URL=myhost
      - DOCKER_IN_DOCKER=start
    privileged: true
</code></pre>
<p>When I configure my project I select the following config :</p>
<p><a href="https://i.sstatic.net/SCJzG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SCJzG.png" alt="TeamCity Config" /></a></p>
<p><a href="https://i.sstatic.net/b1fNR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/b1fNR.png" alt="TeamCity Config" /></a></p>
<p>But my build fail with very few detail about whats wrong.</p>
<pre><code>Step 1/2: Test (.NET)
  Running step within Docker container mcr.microsoft.com/dotnet/sdk:5.0
  dotnet test
    Starting: .NET SDK 5.0.408 /usr/bin/dotnet test /opt/buildagent/work/e83eb8da5bf3868c/ImPresent.Tests/ImPresent.Tests.csproj @/opt/buildagent/temp/agentTmp/1.rsp
    in directory: /opt/buildagent/work/e83eb8da5bf3868c
    MSBUILD : error MSB1021: Cannot create an instance of the logger. The given assembly name or codebase was invalid. (0x80131047)
    Switch: TeamCity.MSBuild.Logger.TeamCityMSBuildLogger,/opt/buildagent/plugins/dotnet/tools/msbuild15/TeamCity.MSBuild.Logger.dll;TeamCity;plain
    Process exited with code 1
    Process exited with code 1 (Step: Test (.NET))
  Step Test (.NET) failed
</code></pre>
<p>Do you have any idea of what could be wrong, or how to check logs the have more details ? I ran my tests in the same container on my desktop, they pass.</p>

<docker><testing><dotnet><teamcity>
TeamCity run step in docker
Ombrelin
# TeamCity run step in docker

(Asked by: username_0 on 2022-08-01)

I'm trying to set up TeamCity to run tests on a .NET project. I have installed TeamCity and its agent (with access to docker) using docker compose :
  teamcity:
    image: jetbrains/teamcity-server
    container_name: teamcity
    volumes:
     - /home/arsene/teamcity/data:/data/teamcity_server/datadir
     - /home/arsene/teamcity/logs:/opt/teamcity/logs
    environment:
      - TEAMCITY_HTTPS_PROXY_ENABLED=true
    labels:
      - traefik.http.routers.teamcity.rule=Host(`myhost`)
      - traefik.http.routers.teamcity.tls=true
      - traefik.http.routers.teamcity.tls.certresolver=le   
      - traefik.http.services.teamcity.loadbalancer.server.port=8111

  teamcityagent:
    image: jetbrains/teamcity-agent
    container_name: teamcityagent
    volumes:
     - /home/arsene/teamcity/agent:/data/teamcity_agent/conf
     - /var/run/docker.sock:/var/run/docker.sock
     - /opt/buildagent/work:/opt/buildagent/work
     - /opt/buildagent/temp:/opt/buildagent/temp
    environment:
      - AGENT_NAME=TeamCityRunner
      - SERVER_URL=myhost
      - DOCKER_IN_DOCKER=start
    privileged: true

When I configure my project I select the following config :


But my build fail with very few detail about whats wrong.
Step 1/2: Test (.NET)
  Running step within Docker container mcr.microsoft.com/dotnet/sdk:5.0
  dotnet test
    Starting: .NET SDK 5.0.408 /usr/bin/dotnet test /opt/buildagent/work/e83eb8da5bf3868c/ImPresent.Tests/ImPresent.Tests.csproj @/opt/buildagent/temp/agentTmp/1.rsp
    in directory: /opt/buildagent/work/e83eb8da5bf3868c
    MSBUILD : error MSB1021: Cannot create an instance of the logger. The given assembly name or codebase was invalid. (0x80131047)
    Switch: TeamCity.MSBuild.Logger.TeamCityMSBuildLogger,/opt/buildagent/plugins/dotnet/tools/msbuild15/TeamCity.MSBuild.Logger.dll;TeamCity;plain
    Process exited with code 1
    Process exited with code 1 (Step: Test (.NET))
  Step Test (.NET) failed

Do you have any idea of what could be wrong, or how to check logs the have more details ? I ran my tests in the same container on my desktop, they pass.

**Tags:** docker, testing, dotnet, teamcity


---

## 2 answers

### Answer by username_1 on 2023-04-07. Score: 1

Teamcity agent is totally unable to detect it is running in docker and try to mount its own directories instead of the proper volumes into the launched container for the step (observed from a problem I encountered with a command line step to run a script within a docker environment).
You need to use command line step and do something like this (untested with .Net but should give the idea, you may need to install jq into the agent container too):
MOUNTS=$( docker inspect teamcityagent | jq '.[0].Mounts[] | select(.Destination | contains("/opt/buildagent/")) | "-v \(.Name):\(.Destination)" ' -r | tr '\n' ' ')
docker pull mcr.microsoft.com/dotnet/sdk:5.0
docker run --rm $MOUNTS -w %teamcity.build.workingDir% mcr.microsoft.com/dotnet/sdk:5.0 /usr/bin/dotnet test %teamcity.build.workingDir%/ImPresent.Tests/ImPresent.Tests.csproj


---

### Answer by username_2 on 2022-11-07. Score: 0

Two things I would try:

1. Add "Build" Step before testing:

   Runner Type: `.NET`.

   Command: `build`.

   Also it may be required to add another build configuration to `Restore` the project before build.
2. Execute this build step in "verbose" mode to get more logging information.


---

