What is Docker?
Docker is an open-source platform that enables developers to package
applications into containers — standardized, executable components that
combine application source code with the operating system (OS) libraries
and dependencies required to run that code in any environment.
Why Use Docker?
- Consistency: Runs the same across all machines (development, test, production).
- Isolation: Applications run in separate containers without interfering.
- Portability: “Build once, run anywhere” approach.
- Efficiency: Lightweight compared to virtual machines.
- Scalability: Easy to scale up or down.
- Rapid Deployment: Containers start almost instantly.
Basic Example: Running a Simple Web Server
First, install Docker Desktop for your OS from docker.com.
Step 2: Verify Installation
This shows the installed Docker version.
Step 3: Pull an Image
Let’s use the official Nginx image:
docker pull
: Command to download an image.nginx
: Name of the image (from Docker Hub).
Step 4: Run a Container
docker run
: Creates and starts a container.-d
: Runs in detached mode (background).-p 8080:80
: Maps host port 8080 to container port 80.--name my-nginx
: Names the container "my-nginx".nginx
: The image to use.
Step 5: Verify the Container is Running
Shows running containers. You should see “my-nginx” listed.
Step 6: Access the Web Server
Open a browser and go to
http://localhost:8080
. You should see the Nginx welcome page.Step 7: Stop the Container
Stops the running container.
Step 8: Remove the Container
Removes the stopped container.
Key Docker Commands Explained
docker images
: Lists all downloaded images.docker ps -a
: Shows all containers (running and stopped).docker exec -it my-nginx bash
: Opens an interactive terminal in a running container.docker logs my-nginx
: Shows logs from a container.docker build -t my-app .
: Builds an image from a Dockerfile in current directory.docker rmi nginx
: Removes an image.
Next Steps
- Learn about Dockerfiles to create custom images.
- Explore Docker Compose for multi-container applications.
- Study Docker volumes for persistent data storage.
- Investigate Docker networking for container communication.
0 Comments