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
Copy file name to clipboardExpand all lines: docker-zero-to-hero/README.md
+84-3Lines changed: 84 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,8 +44,6 @@ There are three important components:
44
44
45
45
### Docker Daemon
46
46
47
-
### Docker Daemon
48
-
49
47
The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.
**Note:** NGINX listens on port 80 inside the container. The `docker run -p 3000:80` option maps container port 80 to host port 3000. You can access the container at `localhost:3000`, even without `EXPOSE 3000` in your Dockerfile.
247
+
248
248
### How Docker Works Internally
249
249
250
250
1. When you run `docker build`, Docker reads the `Dockerfile` line by line and uses your current folder as the build context.
@@ -275,6 +275,85 @@ docker ps
275
275
276
276
14. When you push an image, Docker checks which layers are already in the registry. It only uploads what's missing.
277
277
278
+
### Docker Networking
279
+
280
+
Networking allows containers to communicate with each other and with the host system. Containers run isolated from the host system and need a way to communicate with each other and with the host system.
281
+
282
+
Containers have networking enabled by default, and they can make outgoing connections.
283
+
284
+
**Bridge:** The default network driver. If you don't specify a driver, this is the type of network you are creating. Bridge networks are commonly used when your application runs in a container that needs to communicate with other containers on the same host.
285
+
286
+
**Host:** Removes network isolation between the container and the Docker host, and uses the host's networking directly. (Not supported on macOS/Windows)
287
+
288
+
**None:** Completely isolates a container from the host and other containers. `none` is not available for Swarm services.
289
+
290
+
**Overlay:** Overlay networks connect multiple Docker daemons together and enable Swarm services and containers to communicate across nodes. This strategy removes the need to do OS-level routing.
291
+
292
+
**Macvlan:** Macvlan networks allow you to assign a MAC address to a container, making it appear as a physical device on your network. The Docker daemon routes traffic to containers by their MAC addresses. Using the macvlan driver is sometimes the best choice when dealing with legacy applications that expect to be directly connected to the physical network, rather than routed through the Docker host's network stack.
293
+
294
+
#### Example Commands
295
+
296
+
```bash
297
+
# Start a busybox container as root
298
+
docker run -itd --user root busybox sh
299
+
docker exec -it <container_id> sh
300
+
301
+
>**Note:** While ping inside container i.e `ping google.com` If you get 'ping: permission denied', use --privileged as below.
302
+
303
+
docker run -itd --privileged busybox sh
304
+
docker exec -it <container_id> sh
305
+
306
+
# List networks
307
+
docker network ls
308
+
# Inspect the bridge network
309
+
docker network inspect bridge
310
+
# Create a bridge network
311
+
docker network create my-bridge
312
+
# Run containers on the custom bridge network
313
+
docker run --network my-bridge --name container1 -d nginx
314
+
docker run --network my-bridge --name container2 -d alpine sleep 3600
315
+
docker exec -it container2 ping container1
316
+
317
+
# Run with host network (Linux only)
318
+
docker run --network host -d nginx
319
+
```
320
+
321
+
> **Note:** On macOS and Windows, the `--network host` option is not supported because Docker Desktop uses a virtualized environment and does not provide the host network driver. This option only works natively on Linux. When you run `docker run --network host ...` on macOS or Windows, the container will exit or fail because it cannot use the host network mode.
322
+
323
+
### Docker Compose
324
+
325
+
Docker Compose is a tool for defining and running multi-container applications. It streamlines development and deployment by allowing you to manage services in a single YAML file.
326
+
327
+
**Why use Compose?**
328
+
329
+
-**Simplified control:** Define and manage multi-container apps in one YAML file, streamlining orchestration and replication.
330
+
-**Efficient collaboration:** Shareable YAML files support smooth collaboration between developers and operations, improving workflows and issue resolution.
331
+
-**Rapid application development:** Compose caches the configuration used to create a container. When you restart a service that has not changed, Compose re-uses the existing containers, allowing quick environment changes.
332
+
-**Portability across environments:** Compose supports variables in the Compose file, enabling customization for different environments or users.
333
+
334
+
**How Compose works:**
335
+
With Docker Compose, you use a YAML configuration file (the Compose file) to configure your application's services, then create and start all the services from your configuration with the Compose CLI.
336
+
337
+
> **Note:** The `version` key is obsolete in Compose v2+ and can be omitted.
> **Note:** A basic backend package has been generated with Express and an entry point (index.js). Dependencies are installed and ready for use in your Docker Compose setup. You can now run docker compose up
349
+
350
+
```bash
351
+
docker compose up
352
+
docker compose down
353
+
docker compose logs
354
+
docker compose ps
355
+
```
356
+
278
357
---
279
358
280
359
## Summary
@@ -285,6 +364,8 @@ This guide covers Docker from basics to advanced concepts including:
285
364
- Creating and managing Docker images
286
365
- Multi-stage builds for optimized production images
287
366
- Internal workings of Docker
367
+
- Docker networking
368
+
- Docker compose
288
369
289
370
For more advanced topics, refer to the official [Docker Documentation](https://docs.docker.com/).
0 commit comments