Ravindra BagaleCourses & study guides मराठी

Ravi Sir's Cards › DevOps

DevOps

Chapter 49: Docker Containers: Lifecycle, docker run Flags, exec, logs, Restart Policies, Limits and Every Container Command: Cards

मराठी cards · Open the chapter

Revision cards

Container lifecycle. You must know why a container is not running.
Revision card 1 of 11: Container lifecycle · Download PNG · Open card page

Lesson: 49.1 Container lifecycle: created, running, paused, stopped, removed

Important docker run flags. Most of Docker is docker run with the right flags.
Revision card 2 of 11: Important docker run flags · Download PNG · Open card page

Lesson: 49.2 docker run and its most important flags

exec, attach and logs. You need to look inside a live container.
Revision card 3 of 11: exec, attach and logs · Download PNG · Open card page

Lesson: 49.3 exec, attach and logs: get inside and read output

inspect, stats, top, port, diff, events. Facts beat guesses when debugging.
Revision card 4 of 11: inspect, stats, top, port, diff, events · Download PNG · Open card page

Lesson: 49.4 inspect, stats, top, port, diff and events

Restart policies. Apps crash and servers reboot.
Revision card 5 of 11: Restart policies · Download PNG · Open card page

Lesson: 49.5 Restart policies

CPU and memory limits. One leaky container can crash every other app.
Revision card 6 of 11: CPU and memory limits · Download PNG · Open card page

Lesson: 49.6 Resource limits: memory, CPU, pids and IO

cp, commit, rename, update, wait. Small daily jobs need small commands.
Revision card 7 of 11: cp, commit, rename, update, wait · Download PNG · Open card page

Lesson: 49.7 cp, commit, rename, update, wait and export

Container logging drivers. Unlimited logs can fill a disk.
Revision card 8 of 11: Container logging drivers · Download PNG · Open card page

Lesson: 49.8 Logging drivers and log rotation

Every docker container command. Quick recall saves time on call.
Revision card 9 of 11: Every docker container command · Download PNG · Open card page

Lesson: 49.9 Every docker container command: full reference

PID 1, tini and graceful shutdown. Apps that ignore SIGTERM get killed after 10 seconds and lose requests.
Revision card 10 of 11: PID 1, tini and graceful shutdown · Download PNG · Open card page

Lesson: 49.10 PID 1, tini (--init) and graceful SIGTERM shutdown

Container exits at once; reaching the host. A container lives only while its main process runs.
Revision card 11 of 11: Container exits at once; reaching the host · Download PNG · Open card page

Lesson: 49.11 Container exits immediately, and reaching the host (host.docker.internal on Linux)

Interview cards

Explain the container lifecycle. create makes it, start runs PID 1, stop sends SIGTERM then SIGKILL after 10s, rm deletes it. run = create + start.
Interview card 1 of 11: Explain the container lifecycle. · Download PNG · Open card page

Lesson: 49.1 Container lifecycle: created, running, paused, stopped, removed

Explain common docker run flags. -d background, --name, -p host:container, -e/--env-file, -v, --network, --restart, --rm, -it.
Interview card 2 of 11: Explain common docker run flags. · Download PNG · Open card page

Lesson: 49.2 docker run and its most important flags

exec vs attach? exec runs a new process (safe to exit). attach connects to PID 1; Ctrl+C can stop the container (detach with Ctrl+P Ctrl+Q).
Interview card 3 of 11: exec vs attach? · Download PNG · Open card page

Lesson: 49.3 exec, attach and logs: get inside and read output

How do you check a container's IP and memory use? docker inspect -f with a Go template for the IP; docker stats --no-stream for CPU and memory.
Interview card 4 of 11: How do you check a container's IP and memory use? · Download PNG · Open card page

Lesson: 49.4 inspect, stats, top, port, diff and events

always vs unless-stopped? Both restart on crash and daemon start; unless-stopped stays down after you run docker stop, always comes back after a daemon restart.
Interview card 5 of 11: always vs unless-stopped? · Download PNG · Open card page

Lesson: 49.5 Restart policies

What happens when a container hits its memory limit? The kernel OOM-kills it (exit 137, OOMKilled=true). CPU limits only throttle, they do not kill.
Interview card 6 of 11: What happens when a container hits its memory limit? · Download PNG · Open card page

Lesson: 49.6 Resource limits: memory, CPU, pids and IO

Why not use docker commit in production? A committed image is not repeatable: no Dockerfile, hidden changes, hard to review. Use it only to save a debug state.
Interview card 7 of 11: Why not use docker commit in production? · Download PNG · Open card page

Lesson: 49.7 cp, commit, rename, update, wait and export

How do you stop container logs filling the disk? Set --log-opt max-size=10m --log-opt max-file=3, or default it in daemon.json, or use the local driver.
Interview card 8 of 11: How do you stop container logs filling the disk? · Download PNG · Open card page

Lesson: 49.8 Logging drivers and log rotation

stop vs kill? stop sends SIGTERM and waits (default 10s) before SIGKILL; kill sends SIGKILL at once (or --signal).
Interview card 9 of 11: stop vs kill? · Download PNG · Open card page

Lesson: 49.9 Every docker container command: full reference

Why does docker stop take 10 seconds? PID 1 did not handle SIGTERM, so Docker sent SIGKILL after the timeout.
Interview card 10 of 11: Why does docker stop take 10 seconds? · Download PNG · Open card page

Lesson: 49.10 PID 1, tini (--init) and graceful SIGTERM shutdown

Why does my container exit immediately? Its main process ended or crashed; check docker logs and the exit code.
Interview card 11 of 11: Why does my container exit immediately? · Download PNG · Open card page

Lesson: 49.11 Container exits immediately, and reaching the host (host.docker.internal on Linux)

Comparison cards

docker exec vs docker attach. exec: starts a new process inside.attach: joins the main process.
Comparison card 1 of 3: docker exec vs docker attach · Download PNG · Open card page

Lesson: 49.3 exec, attach and logs: get inside and read output

docker stop vs docker kill. stop: SIGTERM, wait, then SIGKILL.kill: SIGKILL now.
Comparison card 2 of 3: docker stop vs docker kill · Download PNG · Open card page

Lesson: 49.9 Every docker container command: full reference

always vs unless-stopped. always: restart every time.unless-stopped: restart unless you stopped it.
Comparison card 3 of 3: always vs unless-stopped · Download PNG · Open card page

Lesson: 49.5 Restart policies