diff --git a/src/Testcontainers.MySql/MySqlBuilder.cs b/src/Testcontainers.MySql/MySqlBuilder.cs index 4ed177c30..91bfc5a9c 100644 --- a/src/Testcontainers.MySql/MySqlBuilder.cs +++ b/src/Testcontainers.MySql/MySqlBuilder.cs @@ -90,7 +90,7 @@ protected override MySqlBuilder Init() .WithDatabase(DefaultDatabase) .WithUsername(DefaultUsername) .WithPassword(DefaultPassword) - .WithStartupCallback((container, ct) => container.WriteConfigurationFileAsync(ct)); + .WithStartupCallback((container, ct) => Task.WhenAll(container.CreateMySqlFilesDirectoryAsync(ct), container.WriteConfigurationFileAsync(ct))); } /// diff --git a/src/Testcontainers.MySql/MySqlContainer.cs b/src/Testcontainers.MySql/MySqlContainer.cs index d18ffa3db..209625cda 100644 --- a/src/Testcontainers.MySql/MySqlContainer.cs +++ b/src/Testcontainers.MySql/MySqlContainer.cs @@ -48,6 +48,20 @@ await CopyAsync(Encoding.Default.GetBytes(scriptContent), scriptFilePath, Unix.F .ConfigureAwait(false); } + /// + /// Creates an empty /var/lib/mysql-files directory. + /// + /// + /// The directory does not exist in the MySql 8.0.28 and earlier Docker images, and + /// it is required for the module to start properly. + /// + /// Cancellation token. + /// Task that completes when the directory has been created. + internal Task CreateMySqlFilesDirectoryAsync(CancellationToken ct = default) + { + return ExecAsync(new[] { "mkdir", "/var/lib/mysql-files" }, ct); + } + /// /// Write an unobfuscated MySql configuration file that configures the client /// login path. This prevents warnings in the diff --git a/tests/Testcontainers.MySql.Tests/MySqlContainerTest.cs b/tests/Testcontainers.MySql.Tests/MySqlContainerTest.cs index 11a8e71a9..c5e6d5e3a 100644 --- a/tests/Testcontainers.MySql.Tests/MySqlContainerTest.cs +++ b/tests/Testcontainers.MySql.Tests/MySqlContainerTest.cs @@ -66,4 +66,14 @@ public MySqlRootConfiguration() { } } + + [UsedImplicitly] + public sealed class GitHubIssue1142 : MySqlContainerTest + { + // https://github.com/testcontainers/testcontainers-dotnet/issues/1142. + public GitHubIssue1142() + : base(new MySqlBuilder().WithImage("mysql:8.0.28").Build()) + { + } + } } \ No newline at end of file