Day -02 Docker By Mr Ashok | Online Training | Ashok IT.
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.
- Open your terminal or command prompt and type the following command:
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
- Use the following command to pull a simple Docker image like 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.
- Start a container using the pulled image:
-
Access Your Application:
- Open a web browser and navigate to
http://localhost
. You should see the Nginx welcome page.
- Open a web browser and navigate to
Step 4: Managing Docker Containers
-
List Running Containers:
- To see your active containers, use:
docker ps
- To see your active containers, use:
-
Stopping a Container:
- Stop a running container with the following command, replacing
<container_id>
with the actual ID:docker stop <container_id>
- Stop a running container with the following command, replacing
-
Removing a Container:
- Remove a stopped container using:
docker rm <container_id>
- Remove a stopped container using:
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
- Create a new file named
-
Build the Image:
- Run the following command in the directory containing your Dockerfile:
docker build -t my-nginx-image .
- Run the following command in the directory containing your Dockerfile:
-
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
.
- Start a container from your custom image:
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.