start method
Creates and starts the container, then runs the wait strategy.
Steps:
- Ensures Reaper is running (unless Ryuk is disabled).
- Calls configure (override hook for subclasses).
- Creates the container via DockerClient.createContainer.
- Copies any
_transferableSpecsinto the container. - Starts the container via DockerClient.startContainer.
- Runs
_waitStrategyif one was set.
Returns this after startup is complete.
Throws ContainerStartException or HttpException on failure.
Implementation
Future<DockerContainer> start() async {
if (!testcontainersConfig.ryukDisabled &&
image != testcontainersConfig.ryukImage) {
await Reaper.getInstance();
}
configure();
final containerId = await _dockerClient.createContainer(
image,
command: switch (_command) {
null => null,
final List<String> list => list,
final String cmd => splitCommand(cmd),
_ => throw ArgumentError(
'command must be a String or List<String>, got ${_command.runtimeType}',
),
},
env: _env,
name: _name,
ports: _ports,
volumes: _volumes,
tmpfs: _tmpfs.isNotEmpty ? _tmpfs : null,
network: _network?.name,
networkAliases: _networkAliases,
kwargs: _kwargs.isNotEmpty ? _kwargs : null,
);
_containerId = containerId;
for (final spec in _transferableSpecs) {
await _transferIntoContainer(spec.$1, spec.$2, spec.$3);
}
await _dockerClient.startContainer(containerId);
_cachedStatus = 'running';
await _waitStrategy?.waitUntilReady(this);
return this;
}