I have some C# integration tests that spin up a MySql docker container, build a schema, interact with it and then tear down the container. It works fine when I run dotnet test but fails with Cannot assign requested address /var/run/docker.sock when I try to run it as part of a docker build command.
TestContainer setup:
var testcontainerBuilder = new TestcontainersBuilder<MySqlTestcontainer>()
.WithDatabase(new MySqlTestcontainerConfiguration()
{
Database = MYSQL_DBNAME,
Username = MYSQL_USER,
Password = password,
Port = MYSQL_PORT
})
.WithEnvironment("MYSQL_ROOT_HOST", "%")
.WithOutputConsumer(_outputConsumer)
.WithCleanUp(true);
_container = testcontainerBuilder.Build();
await _container.StartAsync();
Things I've checked:
- port is available
_container.ConnectionStringislocalhost. I suspect this is related.
My suspicion is that the docker build environment can't see the MySql container at localhost.