CMD Command
Dockerfile
In above Dockerfile, CMD does this -
- Runs the go application automatically
- Executes
server.gowhen the container starts - don’t need to type the command manually inside the container
So when run: docker run my_image
Docker internally runs: go run server.go
Important behavior of CMD
CMDtells Docker what to run when the container starts.- Only one
CMDis allowed (last one wins) CMDcan be overridden at runtime
Example: docker run -it my_image bash
➡ This replaces CMD and starts bash instead of go run server.go

Why CMD is useful ?
| Benefit | Explanation |
|---|---|
| Auto start app | Application runs immediately when container starts |
| Cleaner workflow | No need to exec into container |
| Reusable image | Same image runs the app everywhere |
| Best practice | Recommended for app startup |
