createContainer method

  1. @override
Future<String> createContainer(
  1. ContainerSpec spec,
  2. Map<String, String> labels
)
override

Creates a container for spec carrying labels. Returns its id.

labels replaces the spec's own labels: the caller has already merged rig's labels on top of them.

Implementation

@override
Future<String> createContainer(
  ContainerSpec spec,
  Map<String, String> labels,
) async {
  calls.add('create');
  lastCreatedSpec = spec;
  lastCreatedLabels = Map.of(labels);

  final id = 'fake${_nextId++}';
  final networkName = spec.network?.dockerName;
  if (networkName != null) {
    _networksByName
        .putIfAbsent(
          networkName,
          () => _FakeNetwork(id: 'net${_nextId++}', name: networkName),
        )
        .connectedContainerIds
        .add(id);
  }
  _containers[id] = _FakeContainer(
    id: id,
    image: spec.image,
    running: false,
    state: 'created',
    labels: Map.of(labels),
    created: DateTime.utc(2026, 1, 1),
    hostPorts: {for (final port in spec.exposedPorts) port: nextHostPort++},
    health: spec.healthcheck == null ? [] : [...healthAfterCreate],
    logs: '',
    network: networkName,
  );
  return id;
}