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 all the running continers. 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:
@@ -84,7 +106,7 @@ 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
+
120
190
**Expected Output:**
121
191
```console
122
192
Active Internet connections (only servers)
@@ -132,9 +202,11 @@ tcp 0 0 :::3000 :::* LISTEN
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
@@ -197,6 +269,7 @@ 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 vefity 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,6 +291,10 @@ 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`
0 commit comments