Cloud and DevOps · Chapter 2
Starting, shrinking and limiting containers
About this chapter
An image that runs on a laptop still has to behave in production. This chapter takes one small API container and makes it ready: starting the right process and stopping it cleanly, shrinking the image with multi-stage builds, running as a user that is not root, passing configuration in instead of baking it in, and adding health checks, memory limits, log limits and the commands to look inside it while it runs.
Who it is for: Developers who can build and run a Docker image and now need to make it small, safe and predictable enough for a real environment.
You will be able to
- Explain the difference between CMD and ENTRYPOINT and why the exec form matters for stopping a container.
- Write a multi-stage Dockerfile that leaves build tools out of the final image.
- Run a container without root and pass its settings in when it starts.
- Add a health check and set limits on memory, processor time and log size.
- Use logs and exec to find out what is happening inside a running container.
The key idea: A container that merely runs is not ready for production. It also has to stop when asked, leave little for an attacker to use, stay within the resources it was given, and tell you when it is unwell.
In this chapter
- What this chapter adds
- CMD and ENTRYPOINT
- Multi-stage builds
- Security basics
- One image, many environments
- Health checks and restart policies
- Resource limits
- Logs: standard output and a limit
- Debugging a running container
- Mistakes that recur
Locked: needs a plan
You can read chapter 1 free. Chapter 2 is the next one.
What you can do now, free: re-read chapter 1 and try its problems.
What a plan gives you: all chapters of the track you pick and their checks. Professional, one role is ₹329 a month or ₹2,299 a year. It renews until you cancel, and you can cancel any time. Paid plans open at launch.
Why is this locked?
Chapter 1 of every track is free, so you can see how the track reads. The rest of a track and its checks come with a plan, or open as you pass each chapter's check.
The price is for one period, a month or a year. A plan renews until you cancel.