0

I created tests for my application using docker inside the dotnet tests. It pulls an image from rabbitmq and starts it before testing and it works fine.

Now I'm trying to add these tests to docker, but to run docker inside a container I'm using volumes in docker.sock to transmit the commands to the host machine.

-v /var/run/docker.sock:/var/run/docker.sock

and to make it easier I would like to add this command in docker compose.

the problem is that the tests run correctly using the command

docker run -v /var/run/docker.sock:/var/run/docker.sock -ti rabbitmq-dotnet-app-tests

but it gives the following error using docker-compose

rabbitmq-dotnet-app-tests-1 | Failed tests.DummyTests.RabbitMqTest1.test1 [1 ms] rabbitmq-dotnet-app-tests-1 | Error Message: rabbitmq-dotnet-app-tests-1 | System.AggregateException : One or more errors occurred. (One or more errors occurred. (Initialization has been cancelled.)) (The following constructor parameters did not have matching fixture data: RabbitMqFixture rabbitMqFixture) rabbitmq-dotnet-app-tests-1 | ---- System.AggregateException : One or more errors occurred. (Initialization has been cancelled.) rabbitmq-dotnet-app-tests-1 | -------- DotNet.Testcontainers.Containers.ResourceReaperException : Initialization has been cancelled. rabbitmq-dotnet-app-tests-1 | ---- The following constructor parameters did not have matching fixture data: RabbitMqFixture rabbitMqFixture

my docker compose file

version: "3.8"

services:
  app-tests:
    image: rabbitmq-dotnet-app-tests
    build:
      context: .
      dockerfile: Dockerfile.Tests
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

here is the github link of this application

Im using docker desktop for windows and the test connectionstring is here

matmahnke
  • 432
  • 3
  • 10
  • If you're trying to start a RabbitMQ container, can you start it in the Dockerfile, set an environment variable to point at it, and not provide the Docker socket to the container? There are significant security concerns around using the Docker socket, and significant portability concerns around trying to dynamically start containers. – David Maze Dec 17 '22 at 15:55
  • @DavidMaze the biggest highlight of this application is starting a container when executing the tests, if I start rabbitmq in the dockerfile I won't be able to integrate with the tests in visual studio. In your opinion does this make sense? is there a better way to do this kind of integration testing? – matmahnke Dec 17 '22 at 16:03
  • 2
    Without doing anything Docker-specific, I'm guessing your application has some way to configure the location of the RabbitMQ broker. For an integration test, can you start a RabbitMQ (maybe in Docker with published `ports:`), point your test framework at this running message broker, and run the tests? Again, there's nothing Docker-specific in this setup beyond optionally running the dependency there. – David Maze Dec 17 '22 at 16:07

0 Answers0