我能够通过扩展默认值PostgreSQLContainer
并更改containerIsStarted
方法来解决此问题:
public class CustomPostgreSQLContainer<SELF extends CustomPostgreSQLContainer<SELF>> extends PostgreSQLContainer<SELF> {
private static final Logger log = LoggerFactory.getLogger(CustomPostgreSQLContainer.class);
public CustomPostgreSQLContainer() {
super("postgres:12");
}
@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
try {
log.debug("M=containerIsStarted, creating database namespace folders and setting permissions");
execInContainer("mkdir", "/tsd01");
execInContainer("chown", "-R", "postgres.postgres", "/tsd01/");
execInContainer("mkdir", "/tsi01");
execInContainer("chown", "-R", "postgres.postgres", "/tsi01/");
execInContainer("mkdir", "/tsisecurity01");
execInContainer("chown", "-R", "postgres.postgres", "/tsisecurity01/");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
super.containerIsStarted(containerInfo);
}
}