Docker Fundamentals

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.

  1. Pulling Images: Use the docker pull command to download images from Docker Hub:
  2. docker pull nginx
  3. Listing Images: View downloaded images on your system with:
  4. docker images
  5. Removing Images: To delete an image, use:
  6. docker rmi <image_id>

Creating and Managing Containers

Containers are instances of Docker images that can be started, stopped, and customized to run applications.

  1. Running a Container: Create and start a container with:
  2. 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.

  3. Listing Containers: View running containers with:
  4. docker ps

    To view all containers (including stopped ones), use:

    docker ps -a
  5. Stopping a Container: Stop a running container by its ID or name:
  6. docker stop <container_id>
  7. Removing a Container: Remove a stopped container with:
  8. 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
  • View Docker System Information:
  • docker info
  • Search for Images:
  • docker search <image_name>
  • Inspect a Container: Get detailed information about a container:
  • docker inspect <container_id>
  • View Logs: Check container logs:
  • 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.

Post a Comment

0 Comments