Welcome to your first practical step into the world of containerization! Docker is an open platform for developing, shipping, and running applications. It enables you to separate your applications from your infrastructure so you can deliver software quickly. If you haven't already, you might want to review What is Containerization? to understand the "why" behind Docker.
Docker is available for Windows, macOS, and various Linux distributions. The installation process is straightforward:
Once Docker is installed, you can verify it by running a few simple commands in your terminal or command prompt:
docker --version
This command should output the installed Docker version, confirming the CLI is working.
This is the traditional first step to ensure Docker is running correctly. The `hello-world` image is a tiny image designed to test your Docker installation.
docker run hello-world
If successful, you'll see a message explaining that your installation appears to be working correctly. This command performs several actions:
We'll dive deeper into these in the Docker Deep Dive section, but here’s a quick introduction:
Here are a few essential commands to get you started:
docker pull <image_name>
: Downloads an image from a registry (Docker Hub by default).
docker pull nginx
docker images
: Lists all images stored locally.docker run [OPTIONS] <image_name> [COMMAND] [ARG...]
: Creates and starts a new container from an image.
docker run -d -p 8080:80 --name my-nginx nginx
This command runs an Nginx container:
-d
: Runs the container in detached mode (in the background).-p 8080:80
: Maps port 8080 on the host to port 80 in the container.--name my-nginx
: Assigns a custom name to your container.nginx
: Specifies the image to use.http://localhost:8080
in your browser.
docker ps
: Lists running containers. Add -a
(docker ps -a
) to see all containers (including stopped ones).docker stop <container_id_or_name>
: Stops a running container.docker rm <container_id_or_name>
: Removes a stopped container.docker rmi <image_id_or_name>
: Removes an image.Congratulations! You've taken your first steps with Docker. You can now pull images, run containers, and manage them. This foundation is crucial for understanding more advanced topics.
To continue your journey and explore Docker in more detail, including how to build your own images with Dockerfiles and manage container data, head over to our Docker Deep Dive section.
Understanding Docker is a key part of Modern DevOps Practices and can be complemented by exploring technologies like WebAssembly for different types of application portability.