Introduction
Now that you understand the theoretical underpinnings of Docker and containers, it's time to get hands-on. This lesson will guide you through the process of installing Docker Desktop on your operating system and then introduce you to the fundamental Docker commands. You'll learn how to verify your installation, pull your first image, and run a simple container.
Key Concepts
Docker Desktop Installation
Docker Desktop is an easy-to-install application for Mac, Windows, or Linux that enables youn to build and share containerized applications and microservices. It includes Docker Engine, Docker CLI client, Docker Compose, Kubernetes, and other essential tools.
- Installation Steps (General):
-
Download Docker Desktop from the official Docker website.
-
Run the installer and follow the on-screen instructions.
-
Ensure Docker Desktop is running after installation.
Verifying Docker Installation
Once installed, you can verify that Docker is correctly set up by running a simple command in your terminal or command prompt.
Example/Code
To check the Docker version:
bashdocker --version docker info
Running Your First Container
Docker provides a command to quickly run a test container. The docker run command will pull an image (if not available locally) and start a container from it.
bashdocker run hello-world
This command will download the hello-world image from Docker Hub (the default public registry) and run a container that prints a message indicating Docker is working correctly.
Basic Docker Commands
-
docker pull [image_name]: Downloads an image from a registry (e.g., Docker Hub) to your local machine. -
docker images: Lists all images stored locally on your machine. -
docker ps: Lists all currently running containers. -
docker ps -a: Lists all containers, including those that are stopped. -
docker stop [container_id or name]: Stops a running container gracefully. -
docker rm [container_id or name]: Removes a stopped container. -
docker rmi [image_id or name]: Removes an image from your local machine.
Summary/Key Takeaways
-
Docker Desktop provides a comprehensive environment for running Docker on your local machine.
-
docker --versionanddocker infoverify your installation. -
docker runis used to create and start a container from an image. -
Essential commands include
pull,images,ps,stop,rm, andrmifor managing images and containers.