Day -02 Docker By Mr Ashok | Online Training | Ashok IT.

3 min read 4 hours ago
Published on Oct 19, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial is designed to guide you through the foundational concepts of Docker as presented in the video "Day -02 Docker" by Mr. Ashok. Docker is an essential tool for developers and IT professionals, allowing for the creation, deployment, and management of applications within containers. Understanding Docker will enhance your ability to develop scalable applications and facilitate smoother deployment processes.

Step 1: Understanding Docker Fundamentals

  • What is Docker?

    • Docker is a platform that enables developers to automate the deployment of applications inside lightweight, portable containers.
  • Key Concepts:

    • Containers: Encapsulated environments that include everything needed to run an application.
    • Images: Read-only templates used to create containers. Images can be versioned and shared.
    • Docker Engine: The runtime that allows you to build and run containers.

Step 2: Installing Docker

  • Download Docker:

    • Visit the official Docker website Docker Download to download the appropriate version for your operating system (Windows, macOS, Linux).
  • Install Docker:

    • Follow the installation instructions for your platform. Ensure that you enable WSL 2 integration if you are using Windows.
  • Verify Installation:

    • Open your terminal or command prompt and type the following command:
      docker --version
      
    • This command should return the installed Docker version, confirming that the installation was successful.

Step 3: Running Your First Container

  • Pull a Docker Image:

    • Use the following command to pull a simple Docker image like Nginx:
      docker pull nginx
      
  • Run the Container:

    • Start a container using the pulled image:
      docker run -d -p 80:80 nginx
      
    • This command runs Nginx in detached mode and maps port 80 of the container to port 80 on your host machine.
  • Access Your Application:

    • Open a web browser and navigate to http://localhost. You should see the Nginx welcome page.

Step 4: Managing Docker Containers

  • List Running Containers:

    • To see your active containers, use:
      docker ps
      
  • Stopping a Container:

    • Stop a running container with the following command, replacing <container_id> with the actual ID:
      docker stop <container_id>
      
  • Removing a Container:

    • Remove a stopped container using:
      docker rm <container_id>
      

Step 5: Building Your Own Docker Image

  • Create a Dockerfile:

    • Create a new file named Dockerfile in your project directory with the following content:
      FROM nginx
      COPY ./html /usr/share/nginx/html
      
  • Build the Image:

    • Run the following command in the directory containing your Dockerfile:
      docker build -t my-nginx-image .
      
  • Run Your Custom Image:

    • Start a container from your custom image:
      docker run -d -p 8080:80 my-nginx-image
      
    • Access it via http://localhost:8080.

Conclusion

In this tutorial, you learned about Docker's core concepts, how to install it, run your first container, manage Docker containers, and create your own Docker image. Mastering these steps will significantly enhance your development workflow. For further learning, consider exploring Docker's advanced features like networking, volume management, and Docker Compose for managing multi-container applications.