Docker: containerize your applications
Introduction
Hey there! Let’s talk about Docker - it’s this cool open-source platform that makes deploying apps a breeze through something called containerization. Think of containers as neat little packages that bundle up your application with everything it needs - the code, runtime, tools, and libraries. This way, your app runs the same way no matter where you deploy it.
What makes Docker special? Unlike traditional virtual machines that simulate an entire operating system, Docker containers share the host’s kernel and only isolate the app processes. This makes them super lightweight and quick to start up - perfect when you need to get things running fast!
Here’s why so many developers love Docker:
- Consistency: Your app works the same way everywhere - from your laptop to the production server
- Isolation: Apps and their dependencies stay in their own sandbox, away from your host system
- Portability: Got Docker? Then you can run the containers - on Mac, Windows, Linux, in the cloud, wherever!
- Efficiency: Containers are lightweight and share the host kernel, so they use way fewer resources than VMs
- Scalability: Need more power? Just spin up more containers - it’s that simple
- Versioning: Made a mistake? No problem! You can track changes and roll back to previous versions
Installation
Verify the installation:
|
|
Configuration
Memory Management
For optimal container performance, especially when running memory-intensive applications, you’ll need to enable proper memory management by modifying your boot parameters:
|
|
Storage Location
By default, Docker stores its images and containers in /var/lib/docker
. If you want to change this location (for example, to a larger drive), you can modify Docker’s configuration:
|
|
Alternatively, if you’re using Docker installed via package manager, you can edit:
|
|
Usage
Basic Commands
Pulling Images
Download Docker images from Docker Hub:
|
|
List Images
View all downloaded images:
|
|
Run Containers
Start a container from an image:
|
|
List Containers
View running containers:
|
|
Stop and Remove Containers
|
|
Expose Ports
Map container ports to host ports:
|
|
This maps port 80 in the container to port 8080 on the host.
Mount Volumes
Share data between host and container:
|
|
For named volumes:
|
|
Network Configuration
Create a Network
|
|
Connect Containers
|
|
Build Custom Images
- Create a Dockerfile:
|
|
- Build the image:
|
|
Advanced Container Management
Committing Changes
After making changes to a container, you can create a new image that preserves those changes:
|
|
This is particularly useful for creating custom images based on your modifications.
Viewing Container Differences
To see what files have been changed, added, or deleted in a container compared to its base image:
|
|
The output uses these prefixes:
A
: AddedD
: DeletedC
: Changed
This is extremely helpful for troubleshooting and understanding what modifications have occurred inside a container.
Container Management
View Container Logs
|
|
Execute Commands in Running Containers
|
|
Check Container Resource Usage
|
|
References
Last updated 03 May 2025, 23:40 CEST.