or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

client-management.mdconfig-secrets.mdcontainer-management.mdcontext-management.mderror-handling.mdimage-management.mdindex.mdnetwork-management.mdplugin-management.mdswarm-services.mdsystem-events.mdvolume-management.md

network-management.mddocs/

0

# Network Management

1

2

Docker network creation, configuration, and container connectivity management with support for custom networks, network drivers, and advanced networking features.

3

4

## Capabilities

5

6

### NetworkCollection

7

8

```python { .api }

9

class NetworkCollection:

10

def create(self, name, **kwargs):

11

"""

12

Create a network.

13

14

Args:

15

name (str): Network name

16

**kwargs: Network configuration options

17

18

Returns:

19

Network: Created network instance

20

21

Common kwargs:

22

driver (str): Network driver ('bridge', 'overlay', 'macvlan', etc.)

23

options (dict): Driver-specific options

24

ipam (dict): IP Address Management configuration

25

check_duplicate (bool): Check for duplicate networks

26

internal (bool): Restrict external access

27

labels (dict): Network labels

28

enable_ipv6 (bool): Enable IPv6 networking

29

attachable (bool): Allow manual container attachment

30

scope (str): Network scope ('local', 'global', 'swarm')

31

ingress (bool): Create ingress network

32

"""

33

34

def get(self, network_id):

35

"""

36

Get a network by ID or name.

37

38

Args:

39

network_id (str): Network ID or name

40

41

Returns:

42

Network: Network instance

43

"""

44

45

def list(self, names=None, ids=None, filters=None):

46

"""

47

List networks.

48

49

Args:

50

names (list): Filter by network names

51

ids (list): Filter by network IDs

52

filters (dict): Additional filters

53

54

Returns:

55

list[Network]: List of network instances

56

"""

57

58

def prune(self, filters=None):

59

"""

60

Remove unused networks.

61

62

Args:

63

filters (dict): Filters for pruning

64

65

Returns:

66

dict: Pruning results

67

"""

68

```

69

70

### Network Model

71

72

```python { .api }

73

class Network:

74

"""

75

A Docker network instance.

76

77

Properties:

78

id (str): Network ID

79

name (str): Network name

80

attrs (dict): Raw network attributes

81

"""

82

83

def connect(self, container, **kwargs):

84

"""

85

Connect a container to this network.

86

87

Args:

88

container (Container or str): Container to connect

89

**kwargs: Connection options

90

91

Common kwargs:

92

aliases (list): Network aliases for container

93

links (list): Links to other containers

94

ipv4_address (str): Static IPv4 address

95

ipv6_address (str): Static IPv6 address

96

link_local_ips (list): Link-local IP addresses

97

"""

98

99

def disconnect(self, container, **kwargs):

100

"""

101

Disconnect a container from this network.

102

103

Args:

104

container (Container or str): Container to disconnect

105

**kwargs: Disconnection options

106

107

Common kwargs:

108

force (bool): Force disconnection

109

"""

110

111

def remove(self):

112

"""Remove the network."""

113

```

114

115

## Usage Examples

116

117

```python

118

import docker

119

120

client = docker.from_env()

121

122

# Create custom network

123

network = client.networks.create(

124

'my-app-network',

125

driver='bridge',

126

options={'com.docker.network.bridge.name': 'my-bridge'},

127

ipam={

128

'Config': [{

129

'Subnet': '172.20.0.0/16',

130

'Gateway': '172.20.0.1'

131

}]

132

}

133

)

134

135

# Connect containers

136

container1 = client.containers.run('nginx', detach=True)

137

container2 = client.containers.run('redis', detach=True)

138

139

network.connect(container1, aliases=['web'])

140

network.connect(container2, ipv4_address='172.20.0.10')

141

142

# List networks

143

for net in client.networks.list():

144

print(f"Network: {net.name}, Driver: {net.attrs['Driver']}")

145

```