Containers and Docker Basics
Back to Infrastructure Index
What is a Container?
Container คือคุกขัง software ที่จำกัดการมองเห็น resource ในเครื่องนั้น แยกจากส่วนอื่น ๆ ทำให้เร็ว เพราะไม่มี overhead เหมือนจำลองเครื่อง VM
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. Simply put, a container is a sandboxed process on your machine that is isolated from all other processes on the host machine.
Reference: Docker Documentation
Container Characteristics
To summarize, a container:
- is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI.
- can be run on local machines, virtual machines or deployed to the cloud.
- is portable (can be run on any OS).
- is isolated from other containers and runs its own software, binaries, and configurations.
What is a Container Image?
Container image จะบรรจุ filesystem หรือทุกอย่างที่จำเป็นต่อการรันแอปพลิเคชัน
When running a container, it uses an isolated filesystem. This custom filesystem is provided by a container image. Since the image contains the container’s filesystem, it must contain everything needed to run an application - all dependencies, configurations, scripts, binaries, etc.
Image Components
The image also contains other configuration for the container, such as:
- Environment variables - Configuration values for the runtime
- Default command - What to run when the container starts
- Metadata - Labels, author information, build history
- Dependencies - All required libraries and binaries
- Configuration files - Application settings and scripts
Reference: Docker Images Documentation
Container vs Virtual Machine
| Aspect | Container | Virtual Machine |
|---|---|---|
| Startup | Fast (seconds) | Slower (minutes) |
| Resource Usage | Lightweight | Heavy |
| Isolation | Process-level | Full OS isolation |
| Overhead | Minimal | Significant |
| Portability | High | Medium |
| Size | MBs | GBs |
Key Benefits
- Consistency - Same environment across development, testing, and production
- Efficiency - Lower resource usage compared to VMs
- Portability - Run anywhere that supports containers
- Scalability - Easy to scale up or down
- Speed - Fast startup and deployment times
Related: