Skip to content

Latest commit

 

History

History
176 lines (119 loc) · 8.26 KB

File metadata and controls

176 lines (119 loc) · 8.26 KB

/* Génerer par copilot , je vais ajouter un autre fichier nommer Laravel php and mysql with phpmyadmin in docker*/

Docker for Beginners: A Gentle Introduction

Welcome to the world of Docker! This guide is designed to help absolute beginners understand the fundamentals of Docker and get started with containerization.

What is Docker?

Imagine you're building a complex Lego structure. You wouldn't want to build it directly on the floor, where pieces could get lost or the whole thing could be accidentally knocked over. Instead, you'd use a baseplate to keep everything organized and contained.

Docker is like that baseplate for your software applications. It's a platform that uses containers to package your application and all its dependencies (like libraries, frameworks, and configuration files) into a single, portable unit.

Key Concepts:

  • Containers: Isolated environments that run your applications. They share the host machine's operating system kernel but have their own file system, processes, and network.
  • Images: Read-only templates used to create containers. Think of them as blueprints for your application's environment.
  • Docker Engine: The core software that builds, runs, and manages containers.
  • Docker Hub: A cloud-based registry service where you can find and share Docker images.

Why Use Docker?

  • Consistency: Your application runs the same way, regardless of the environment (development, testing, production).
  • Portability: Containers can run on any machine with Docker installed.
  • Isolation: Containers are isolated from each other and the host system, preventing conflicts.
  • Efficiency: Containers are lightweight and start up quickly.
  • Scalability: Easily scale your application by running multiple containers.
  • Reproducibility: You can easily recreate the same environment.

Getting Started

1. Install Docker

  • Docker Desktop: The easiest way to get started. It's available for Windows, macOS, and Linux. Download it from the official Docker website: https://www.docker.com/products/docker-desktop/
  • Docker Engine: If you are on linux, you can install the docker engine directly.

2. Basic Docker Commands

Here are some essential commands to get you started:

  • docker --version: Check if Docker is installed and see the version.
  • docker run hello-world: Run a simple "hello world" container to test your installation.
  • docker ps: List running containers.
  • docker ps -a: List all containers (running and stopped).
  • docker images: List all downloaded Docker images.
  • docker pull <image_name>: Download an image from Docker Hub (e.g., docker pull ubuntu).
  • docker run <image_name>: Run a container from an image (e.g., docker run ubuntu).
  • docker stop <container_id>: Stop a running container.
  • docker rm <container_id>: Remove a stopped container.
  • docker rmi <image_id>: Remove an image.
  • docker exec -it <container_id> /bin/bash : Access the container shell.

3. Running Your First Container

Let's run a simple Nginx web server container:

  1. docker pull nginx: Download the official Nginx image.
  2. docker run -d -p 8080:80 nginx:
    • -d: Run the container in detached mode (in the background).
    • -p 8080:80: Map port 8080 on your host machine to port 80 inside the container.
    • nginx: The name of the image to run.
  3. Open your web browser and go to http://localhost:8080. You should see the Nginx welcome page!

4. Building Your Own Image (Dockerfile)

A Dockerfile is a text file that contains instructions for building a Docker image. Here's a simple example:

# Use an official Node.js runtime as a parent image
FROM node:16

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in package.json
RUN npm install

# Make port 3000 available to the world outside this container
EXPOSE 3000

# Define environment variable
ENV NAME World

# Run app.js when the container launches
CMD [ "node", "app
# Docker for Beginners: A Gentle Introduction

Welcome to the world of Docker! This guide is designed to help absolute beginners understand the fundamentals of Docker and get started with containerization.

## What is Docker?

Imagine you're building a complex Lego structure. You wouldn't want to build it directly on the floor, where pieces could get lost or the whole thing could be accidentally knocked over. Instead, you'd use a baseplate to keep everything organized and contained.

Docker is like that baseplate for your software applications. It's a platform that uses **containers** to package your application and all its dependencies (like libraries, frameworks, and configuration files) into a single, portable unit.

**Key Concepts:**

*   **Containers:** Isolated environments that run your applications. They share the host machine's operating system kernel but have their own file system, processes, and network.
*   **Images:** Read-only templates used to create containers. Think of them as blueprints for your application's environment.
*   **Docker Engine:** The core software that builds, runs, and manages containers.
*   **Docker Hub:** A cloud-based registry service where you can find and share Docker images.

## Why Use Docker?

*   **Consistency:**  Your application runs the same way, regardless of the environment (development, testing, production).
*   **Portability:**  Containers can run on any machine with Docker installed.
*   **Isolation:**  Containers are isolated from each other and the host system, preventing conflicts.
*   **Efficiency:**  Containers are lightweight and start up quickly.
*   **Scalability:**  Easily scale your application by running multiple containers.
* **Reproducibility:** You can easily recreate the same environment.

## Getting Started

### 1. Install Docker

*   **Docker Desktop:** The easiest way to get started. It's available for Windows, macOS, and Linux. Download it from the official Docker website: [https://www.docker.com/products/docker-desktop/](https://www.docker.com/products/docker-desktop/)
* **Docker Engine:** If you are on linux, you can install the docker engine directly.

### 2. Basic Docker Commands

Here are some essential commands to get you started:

*   **`docker --version`:** Check if Docker is installed and see the version.
*   **`docker run hello-world`:** Run a simple "hello world" container to test your installation.
*   **`docker ps`:** List running containers.
*   **`docker ps -a`:** List all containers (running and stopped).
*   **`docker images`:** List all downloaded Docker images.
*   **`docker pull <image_name>`:** Download an image from Docker Hub (e.g., `docker pull ubuntu`).
*   **`docker run <image_name>`:** Run a container from an image (e.g., `docker run ubuntu`).
*   **`docker stop <container_id>`:** Stop a running container.
*   **`docker rm <container_id>`:** Remove a stopped container.
*   **`docker rmi <image_id>`:** Remove an image.
* **`docker exec -it <container_id> /bin/bash`** : Access the container shell.

### 3. Running Your First Container

Let's run a simple Nginx web server container:

1.  **`docker pull nginx`:** Download the official Nginx image.
2.  **`docker run -d -p 8080:80 nginx`:**
    *   `-d`: Run the container in detached mode (in the background).
    *   `-p 8080:80`: Map port 8080 on your host machine to port 80 inside the container.
    *   `nginx`: The name of the image to run.
3.  Open your web browser and go to `http://localhost:8080`. You should see the Nginx welcome page!

### 4. Building Your Own Image (Dockerfile)

A `Dockerfile` is a text file that contains instructions for building a Docker image. Here's a simple example:

```dockerfile
# Use an official Node.js runtime as a parent image
FROM node:16

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in package.json
RUN npm install

# Make port 3000 available to the world outside this container
EXPOSE 3000

# Define environment variable
ENV NAME World

# Run app.js when the container launches
CMD [ "node", "app.js" ]