# Docker for DevOps Engineers.

Docker is a platform and a set of tools designed to facilitate the development, deployment, and execution of applications within lightweight, portable, and self-sufficient containers. Containers allow developers to package an application and its dependencies together into a single unit, ensuring consistency across different environments.

Here are some key concepts and components of Docker:

1. **Containers:**
    
    * A container is a lightweight, standalone, and executable software package that includes everything needed to run a piece of software, including the code, runtime, libraries, and system tools.
        
    * Containers isolate applications from their environment and ensure consistency in development, testing, and deployment.
        
2. **Docker Image:**
    
    * An image is a lightweight, standalone, and executable package that includes the application and all its dependencies.
        
    * Images are used to create containers. They are often built from a set of instructions defined in a Dockerfile.
        
3. **Dockerfile:**
    
    * A Dockerfile is a text file that contains instructions for building a Docker image. It specifies the base image, sets up the environment, and defines how the application should be run.
        
4. **Docker Engine:**
    
    * The Docker Engine is the core of Docker. It's a client-server application with a REST API that listens for Docker API requests and manages containers.
        
    * It consists of a daemon (the server) and a command-line interface (CLI) client.
        
5. **Docker Compose:**
    
    * Docker Compose is a tool for defining and running multi-container Docker applications.
        
    * It uses a YAML file to configure the application's services, networks, and volumes, making it easy to define and manage complex applications.
        

### Tasks:

### **1\. Use the** `docker run` command to start a new container:

```plaintext
bashCopy codedocker run hello-world
```

This command will download the "hello-world" image from Docker Hub and run a simple container that prints a welcome message. It's a common first step to check if your Docker installation is working.

### **2\. Use the** `docker inspect` command to view detailed information:

```plaintext
bashCopy code# Replace <container_id_or_name> with the actual ID or name of your container
docker inspect <container_id_or_name>
```

This command provides detailed information about a container or image, including its configuration, network settings, and more.

### **3\. Use the** `docker port` command to list port mappings for a container:

```plaintext
bashCopy code# Replace <container_id_or_name> with the actual ID or name of your container
docker port <container_id_or_name>
```

This command shows the mapping of ports between the container and the host machine.

### **4\. Use the** `docker stats` command to view resource usage statistics:

```plaintext
bashCopy code# Replace <container_id_or_name> with the actual ID or name of your container
docker stats <container_id_or_name>
```

This command provides real-time resource usage statistics for one or more containers, including CPU, memory, and network usage.

### **5\. Use the** `docker top` command to view processes inside a container:

```plaintext
bashCopy code# Replace <container_id_or_name> with the actual ID or name of your container
docker top <container_id_or_name>
```

This command shows the processes running inside a container.

### **6\. Use the** `docker save` command to save an image to a tar archive:

```plaintext
bashCopy code# Replace <image_name> with the actual name of your image
docker save -o image.tar <image_name>
```

This command exports a Docker image to a tar archive.

### **7\. Use the** `docker load` command to load an image from a tar archive:

```plaintext
bashCopy codedocker load -i image.tar
```

This command imports a Docker image from a tar archive.
