@@ -113,15 +113,60 @@ default via 10.255.0.123 dev my-bridge0
113
113
/ #
114
114
```
115
115
116
+ Or, in a Docker Compose file:
117
+
118
+ ``` yaml
119
+ version : ' 3'
120
+ services :
121
+ app :
122
+ hostname : my-http
123
+ image : nginx
124
+ mac_address : 86:41:68:f8:85:b9
125
+ networks :
126
+ - dhcp
127
+ networks :
128
+ dhcp :
129
+ external :
130
+ name : my-dhcp-net
131
+ ` ` `
132
+
133
+ The above Compose file assumes your network has already been created with ` docker network create`. **This is the
134
+ recommended way to use `docker-net-dhcp`**, since it allows the network to be shared among multiple compose projects and
135
+ other containers. However, you can also create the network as part of the Compose definition. In this case Docker
136
+ Compose will manage the network itself (for example deleting it when `docker-compose down` is run).
137
+
138
+ ` ` ` yaml
139
+ version: '3'
140
+ services:
141
+ app:
142
+ image: nginx
143
+ hostname: my-server
144
+ networks:
145
+ - dhcp
146
+ networks:
147
+ dhcp:
148
+ driver: ghcr.io/devplayer0/docker-net-dhcp:golang
149
+ driver_opts:
150
+ bridge: my-bridge
151
+ ipam:
152
+ driver: 'null'
153
+ ` ` `
154
+
116
155
Note :
117
156
- It will take a bit longer than usual for the container to start, as a DHCP lease needs to be obtained before creating it
118
157
- Once created, a persistent DHCP client will renew the DHCP lease (and then update the default gateway in the
119
158
container) when necessary - **this client runs separately from the container**
120
159
- Use `--mac-address` to specify a MAC address if you've configured reserved IP addresses on your DHCP server, or if
121
160
you want a container to re-use an old lease
161
+ - Add `--hostname my-host` to have the DHCP transmit this name as the host for the container. This is useful if your
162
+ DHCP server is configured to update DNS records from DHCP leases.
122
163
- If the `docker run` command times out waiting for a lease, you can try increasing the initial timeout value by
123
164
passing `-o lease_timeout=60s` (e.g. to increase to 60 seconds)
124
165
166
+ # # Docker Compose
167
+
168
+ Sample Docker Compose file :
169
+
125
170
# # Debugging
126
171
127
172
To read the plugin's log, do `cat /var/lib/docker/plugins/*/rootfs/var/log/net-dhcp.log` (as `root`). You can also use
0 commit comments