In this post, we’ll dive into the foundational aspects of Docker to ensure you have a solid understanding of its core components. By the end, you’ll be comfortable working with Docker images, managing containers, and using basic Docker CLI commands.
Working with Docker Images
Docker images are the building blocks of containers. They are lightweight, standalone, and include everything needed to run an application.
- Pulling Images: Use the
docker pull
command to download images from Docker Hub: - Listing Images: View downloaded images on your system with:
- Removing Images: To delete an image, use:
docker pull nginx
docker images
docker rmi <image_id>
Creating and Managing Containers
Containers are instances of Docker images that can be started, stopped, and customized to run applications.
- Running a Container: Create and start a container with:
- Listing Containers: View running containers with:
- Stopping a Container: Stop a running container by its ID or name:
- Removing a Container: Remove a stopped container with:
docker run -d -p 80:80 nginx
This command runs the nginx
image in detached mode and maps port 80 on your machine to port 80 in the container.
docker ps
To view all containers (including stopped ones), use:
docker ps -a
docker stop <container_id>
docker rm <container_id>
Basic Docker CLI Commands
The Docker Command-Line Interface (CLI) allows you to interact with Docker. Here are some essential commands:
- Check Docker Version:
docker --version
docker info
docker search <image_name>
docker inspect <container_id>
docker logs <container_id>
Conclusion
Mastering the fundamentals of Docker is the first step toward building, deploying, and managing containerized applications. With a solid grasp of Docker images, containers, and CLI commands, you’re ready to explore more advanced topics and workflows.
0 Comments