You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`-f` or `--format` activates Go template formatting
58
+
-`{{range .NetworkSettings.Networks}}` iterates through networks
59
+
-`{{.IPAddress}}` extracts the IP for each network
60
+
-`{{end}}` closes the loop
61
+
62
+
**Example Output:**
63
+
64
+
(*The container's internal IP in Docker's network*)
65
+
```console
66
+
172.19.0.3
67
+
```
68
+
69
+
Docker uses **Go Templates** for the `--format` filtering in `docker inspect`. You can get more details on how to construct the filter in Go's [text/template](https://pkg.go.dev/text/template) package.
70
+
Also, you can learn more on formatting output in [Format command and log output](https://docs.docker.com/engine/cli/formatting/) section.
71
+
56
72
## 2. Log Analysis
57
73
### Viewing Container Logs
58
74
59
75
```bash
60
-
docker-compose logs
76
+
docker compose logs
77
+
```
78
+
79
+
This will return the logs of containers that are part of the docker compose setup. You can also get the container specific logs using the following command.
80
+
81
+
```bash
82
+
docker compose logs nodejs-app
61
83
```
62
84
63
85
**Example Output (when accessing the service):**
@@ -66,7 +88,7 @@ docker-compose logs
66
88
debug-docker_nodejs-app_1 | Node.js server running on port 3000
67
89
```
68
90
69
-
This confirms your Node.js application launched successfully
91
+
This confirms your Node.js application launched successfully.
70
92
71
93
### Generating Request Logs
72
94
Make a test request to generate logs:
@@ -75,7 +97,7 @@ Make a test request to generate logs:
75
97
curl -v http://localhost:3000
76
98
```
77
99
78
-
After the request, check logs again to see:
100
+
After the request, check the logs again to see:
79
101
80
102
```console
81
103
debug-docker_nodejs-app_1 | Node.js server running on port 3000
@@ -84,10 +106,10 @@ debug-docker_nodejs-app_1 | GET / 200 7.001 ms - 19
- `docker exec`: Runs a command inside a specific container (`nodejs-app`).
184
+
- `netstat -tuln`: A Linux utility to list all listening network ports with the flags:
185
+
- `-t`: Show TCP ports
186
+
- `-u`: Show UDP ports
187
+
- `-l`: Display only listening ports (services accepting connections)
188
+
- `-n`: Show numeric addresses/ports
189
+
190
+
**Example Output:**
121
191
```console
122
192
Active Internet connections (only servers)
123
193
Proto Recv-Q Send-Q Local Address Foreign Address State
124
194
tcp 0 0 :::3000 :::* LISTEN
125
195
```
126
196
127
197
- Shows Node.js listening on port 3000
128
-
- No output means service isn't running properly
198
+
- No output means the service isn't running properly
129
199
130
200
## 4. Interactive Debugging
131
201
### Executing into Containers
132
202
133
203
For Node.js application debugging:
134
204
```bash
135
-
docker exec -it debug-docker_nodejs-app_1 sh
205
+
docker exec -it nodejs-app sh
136
206
```
137
-
Now you can:
207
+
208
+
This gives you full shell access inside the container where you can run any Linux command (as long as the tool exists in the container). Following are few things that you can do.
209
+
138
210
1. Check running processes: `ps aux`
139
211
```bash
140
212
ps aux
@@ -190,13 +262,14 @@ PONG
190
262
docker exec -it debug-docker_nginx_1 nginx -t
191
263
```
192
264
193
-
**Expected Output:**
265
+
**Example Output:**
194
266
```console
195
267
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
196
268
nginx: configuration file /etc/nginx/nginx.conf test is successful
197
269
```
198
270
199
271
## 5. Health Checks and Readiness Probes
272
+
Docker health checks are automated tests that periodically verify if a container is functioning properly. Health checks transform your containers from static processes into self aware services that can catch issues like application crashes, frozen processes, dependency failures, etc.
200
273
Let's enhance our `docker-compose.yml` with health checks:
201
274
202
275
```yaml
@@ -218,12 +291,16 @@ services:
218
291
retries: 3
219
292
```
220
293
294
+
- Docker runs the `test` command at your specified `interval` (e.g., every 30s)
295
+
- The service is marked `healthy` only if the command succeeds (exit code 0)
296
+
- After `retries` consecutive failures, it's marked `unhealthy`
@@ -232,7 +309,7 @@ debug-docker_redis_1 Up 5 minutes (healthy)
232
309
```
233
310
234
311
## 6. Temporary Debug Containers
235
-
Sometimes you need additional tools. Create a temporary debug container in the same network:
312
+
Sometimes you need additional tools that are not part of the containers you are using, for that create a temporary debug container with the needed tools in the same network:
236
313
```bash
237
314
docker run -it --rm --network debug-docker_default alpine sh
238
315
```
@@ -243,7 +320,7 @@ Now from this container you can:
243
320
nslookup nodejs-app
244
321
```
245
322
246
-
**Expected Output:**
323
+
**Example Output:**
247
324
```console
248
325
Server: 127.0.0.11
249
326
Address: 127.0.0.11:53
@@ -261,7 +338,7 @@ Address: 172.19.0.3
261
338
wget -qO- http://nodejs-app:3000
262
339
```
263
340
264
-
**Expected Output:**
341
+
**Example Output:**
265
342
```console
266
343
Hello from Node.js!
267
344
```
@@ -291,10 +368,10 @@ docker stats
291
368
292
369
**Example Output:**
293
370
```console
294
-
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
0 commit comments