addContainer method

String addContainer({
  1. required Map<String, String> labels,
  2. String image = 'scratch:latest',
  3. String state = 'running',
  4. DateTime? created,
  5. Map<int, int> hostPorts = const {},
  6. List<HealthStatus> health = const [],
  7. String logs = '',
  8. String? network,
})

Adds a container that already exists, as if a previous run left it.

network is the Docker network name (the same string passed to addNetwork's name), for a caller that wants removeContainer to free that network's active endpoint again, the way Docker would.

Implementation

String addContainer({
  required Map<String, String> labels,
  String image = 'scratch:latest',
  String state = 'running',
  DateTime? created,
  Map<int, int> hostPorts = const {},
  List<HealthStatus> health = const [],
  String logs = '',
  String? network,
}) {
  final id = 'fake${_nextId++}';
  _containers[id] = _FakeContainer(
    id: id,
    image: image,
    running: state == 'running',
    state: state,
    labels: Map.of(labels),
    created: created ?? DateTime.utc(2026, 1, 1),
    hostPorts: Map.of(hostPorts),
    health: [...health],
    logs: logs,
    network: network,
  );
  return id;
}