start method

Creates and starts the container, then runs the wait strategy.

Steps:

  1. Ensures Reaper is running (unless Ryuk is disabled).
  2. Calls configure (override hook for subclasses).
  3. Creates the container via DockerClient.createContainer.
  4. Copies any _transferableSpecs into the container.
  5. Starts the container via DockerClient.startContainer.
  6. Runs _waitStrategy if 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;
}