Docker Quick Start
This chapter will quickly introduce you to Docker's core features through hands-on operations, running your first container, and understanding basic Docker commands.
Running Your First Container
Hello World Container
Let's start with the simplest example:
Sample Output:
What happened in this process?
- Docker client contacts Docker daemon
- Daemon pulls "hello-world" image from Docker Hub
- Daemon creates new container from image and runs it
- Container outputs message and exits
Running Interactive Container
Parameter Description:
-i: Keep STDIN open-t: Allocate a pseudo-terminalubuntu:20.04: Image name and tag/bin/bash: Command to execute
Operations inside container:
Basic Docker Commands
Image-related Commands
Container-related Commands
Practical Example: Running Web Server
Running Nginx Server
Parameter Description:
-d: Run in background (daemon mode)-p 8080:80: Port mapping, map host's port 8080 to container's port 80--name my-nginx: Specify container name
Verify Service:
Custom Nginx Content
Container Lifecycle Management
Creating and Managing Containers
Container Status Viewing
Data Management Basics
Data Volumes
Bind Mounts
Network Basics
Port Mapping
Container Networks
Practical Exercises: Setting Up Development Environment
Exercise 1: Run Database
Exercise 2: Run Redis Cache
Exercise 3: Run Node.js Application
Common Commands Quick Reference
Image Operations
Container Operations
System Operations
Troubleshooting
Common Issues and Solutions
-
Container Won't Start
-
Port Conflicts
-
Image Pull Fails
-
Container Out of Memory
Best Practice Tips
-
Use Specific Image Tags
-
Clean Up Resources Promptly
-
Use Meaningful Container Names
Chapter Summary
Through this chapter, you have mastered Docker's basic operations:
Key Points:
- Learned to run your first Docker container
- Mastered basic Docker commands
- Understood container lifecycle management
- Learned port mapping and data mounting
- Experienced Docker's convenience through practical examples
You can now:
- Run various pre-built containers
- Manage container startup, stop, and deletion
- Perform basic network and storage configuration
- Troubleshoot common container issues
In the next chapter, we will dive deep into Docker's core concepts, including detailed principles of important concepts like images, containers, and repositories.