# basics

Docker is a platform for developing, shipping, and running applications in containers. Containers allow you to package an application and its dependencies together in a standardized unit for easy deployment across different environments. Here are some basics to get you started with Docker:

#### 1. **Install Docker:**

* Install Docker on your machine by following the instructions on the [official Docker website](https://docs.docker.com/get-docker/).

#### 2. **Docker Concepts:**

* **Image:** A lightweight, standalone, and executable package that includes everything needed to run a piece of software, including the code, runtime, libraries, and system tools.
* **Container:** An instance of a Docker image, running as a process on the host machine.

#### 3. **Docker Commands:**

* **Pull an Image:**

  ```bash
  docker pull image_name:tag
  ```
* **Run a Container:**

  ```bash
  docker run image_name:tag
  ```
* **List Running Containers:**

  ```bash
  docker ps
  ```
* **List All Containers (including stopped ones):**

  ```bash
  docker ps -a
  ```
* **Stop a Running Container:**

  ```bash
  docker stop container_id
  ```
* **Remove a Container:**

  ```bash
  docker rm container_id
  ```
* **List Docker Images:**

  ```bash
  docker images
  ```
* **Remove an Image:**

  ```bash
  docker rmi image_id
  ```

#### 4. **Dockerfile:**

* Create a Dockerfile to define how your image should be built. Here's a basic example:

  ```Dockerfile
  # Use an official base image
  FROM nginx:latest

  # Copy your application code
  COPY . /usr/share/nginx/html

  # Expose a port
  EXPOSE 80

  # Define the command to run your application
  CMD ["nginx", "-g", "daemon off;"]
  ```

#### 5. **Build a Docker Image:**

* Navigate to the directory containing your Dockerfile and run:

  ```bash
  docker build -t image_name:tag .
  ```

#### 6. **Run a Container from a Built Image:**

* After building your image, run a container:

  ```bash
  docker run -p 8080:80 image_name:tag
  ```

This example maps port 8080 on your host machine to port 80 in the container.

#### 7. **Docker Volumes:**

* Use volumes to persist data outside the container:

  ```bash
  docker run -v /path/on/host:/path/in/container image_name:tag
  ```

#### 8. **Docker Compose:**

* Docker Compose allows you to define and run multi-container Docker applications. Create a `docker-compose.yml` file to specify services, networks, and volumes.

#### 9. **Networking:**

* Docker containers can communicate with each other using container names or through defined networks.

#### 10. **Docker Hub:**

* Docker Hub is a registry service where you can find and share container images.

#### 11. **Docker Cheat Sheet:**

* Refer to the official [Docker Cheat Sheet](https://www.docker.com/sites/default/files/d8/2019-09/docker-cheat-sheet.pdf) for quick reference.

#### Additional Resources:

* [Docker Documentation](https://docs.docker.com/)
* [Docker Getting Started](https://docs.docker.com/get-started/)

Practice running containers, building images, and exploring more advanced features as you become more comfortable with Docker. It's a powerful tool for containerization and can significantly simplify application deployment and management.
