# Image ## πŸ”§ 1. **Build Image & Check Image** ### βœ… Build image from Dockerfile: ```bash docker build -t my_image_name . ``` ### βœ… List all local images: ```bash docker images ``` ### βœ… Inspect image details: ```bash docker inspect my_image_name ``` --- # Container ## πŸš€ 2. **Run Container, Check & Enter** ### βœ… Run a container: ```bash docker run -d --name my_container_name my_image_name ``` ### βœ… List running containers: ```bash docker ps ``` ### βœ… List all containers (including stopped): ```bash docker ps -a ``` ### βœ… Enter running container: ```bash docker exec -it my_container_name bash # Or use sh if bash not available: docker exec -it my_container_name sh ``` ### βœ… View container logs: ```bash docker logs my_container_name ``` --- # Volume ## πŸ“¦ 3. **Volume Setup, Functioning, Management** ### βœ… List all volumes: ```bash docker volume ls ``` ### βœ… Inspect specific volume: ```bash docker volume inspect my_volume_name ``` ### βœ… Bind-mount or use named volume in run: ```bash docker run -v my_volume_name:/path/in/container ... ``` ### βœ… Check if volume data persists: * Create a file inside the mounted path in container. * Stop container. * Start new container with same volume and verify the file. --- # nginx ## 🌐 4. **Check Nginx Setup** ### βœ… Run nginx container with config: ```bash docker run -d -p 80:80 --name nginx_container nginx ``` ### βœ… Check container logs (for errors): ```bash docker logs nginx_container ``` ### βœ… Test from host machine: ```bash curl http://localhost ``` ### βœ… Test Nginx from inside container: ```bash docker exec -it nginx_container curl localhost ``` --- # mairaDB ## πŸ›’ 5. **Check MariaDB Setup** ### βœ… Run MariaDB with env variables: ```bash docker run -d --name mariadb_container -e MYSQL_ROOT_PASSWORD=yourpass mariadb ``` ### βœ… Check logs: ```bash docker logs mariadb_container ``` ### βœ… Connect via client: ```bash docker exec -it mariadb_container mysql -uroot -p ``` ### βœ… List databases: ```sql SHOW DATABASES; ``` --- # wordpress ## 🌐 6. **Check WordPress Setup** ### βœ… Run WordPress linked to MariaDB: Ensure WordPress has correct `WORDPRESS_DB_HOST`, `WORDPRESS_DB_NAME`, etc. ```bash docker run -d --name wp_container -p 8080:80 \ -e WORDPRESS_DB_HOST=mariadb_container:3306 \ -e WORDPRESS_DB_USER=wpuser \ -e WORDPRESS_DB_PASSWORD=wppass \ -e WORDPRESS_DB_NAME=wordpress \ wordpress ``` ### βœ… Check logs: ```bash docker logs wp_container ``` ### βœ… Access WordPress mainpage: ```bash # use command to check curl (-k) http://yilin.fr.42 # OR # launch chromium browser in terminal chromium http://yilin.fr.42 ``` ### βœ… Access WordPress login page (admin): ```bash! # launch chromium browser in terminal chromium http://yilin.fr.42/wp-admin ``` log in with credentials set in .env: ```bash! # WP_URL=https://yilin.42.fr # WP_TITLE=My Inception Site # WP_ADMIN_USER=yilin # WP_ADMIN_PASSWORD=happybirthday # WP_ADMIN_EMAIL=yilin@student.42.fr # WP_USER=hottie # WP_USER_PASSWORD=2hot2handle # WP_USER_EMAIL=hottie@yilin.42.fr ``` > with the settings of username & password, should be able to log in and access to wordpress admin page --- # redis (bonus) ## πŸ” 7. **Check Redis Setup** ### βœ… Run Redis: ```bash docker run -d --name redis_container redis ``` ### βœ… Connect to Redis CLI: ```bash docker exec -it redis_container redis-cli ``` > this command initiate a promt ### βœ… Test Redis commands: ```bash SET [key] [value] GET [key] # Example input/output: SET iam hottie GET iam > "hottie" ``` > this means successfully created a key&value in cache # adminer (bonus) ## βœ… go to adminer site ```bash # launch chromium browser in terminal chromium http://yilin.fr.42/adminer ``` ## βœ… log in with credentials set in `.env` ```bash # MYSQL_HOSTNAME=mariadb # MYSQL_DATABASE=wordpress # MYSQL_USER=yilin # MYSQL_ROOT_PASSWORD=happybirthday # MYSQL_PASSWORD=happybirthday # on adminer login page: System: MySQL / mariaDB Server: mariadb Username: yilin Password: happybirthday Database: wordpress ``` --- # Cleanups ## 🧹 8. **Final Cleanup Commands** ### βœ… Stop all containers: ```bash docker stop $(docker ps -q) ``` ### βœ… Remove all containers: 5. πŸ’Ύ What Is Volume & Why Use It? ```bash docker rm $(docker ps -aq) ``` ### βœ… Remove all images: ```bash docker rmi $(docker images -q) ``` ### βœ… Remove all volumes: ```bash docker volume rm $(docker volume ls -q) ``` ### βœ… Remove dangling (unused) data: ```bash docker system prune -a --volumes ``` --- # General important concept briefs ## πŸ”— **How Do Nginx, MariaDB, WordPress, Redis, Adminer Work Together?** ```plaintext +-------------+ +------------+ +----------+ | Browser | ---> | Nginx | <---> | WordPress| +-------------+ +------------+ +----------+ | | +--------+ +--------+ |MariaDB | | Redis | +--------+ +--------+ | +--------+ |Adminer| +--------+ ``` * **Nginx**: Web server. Routes requests to WordPress. * **WordPress**: PHP app. Handles website logic. * **MariaDB**: Stores WordPress data (posts, users). * **Redis**: Speeds up WordPress by caching. * **Adminer**: Lets you log into MariaDB and manage data. > All are connected using **Docker Compose**, each in their own **container**, talking through Docker’s **network**. --- ## πŸ”„ **Analogy for Dockerfile, Image, Container, Docker Compose, App, Environment** ### **πŸ— Analogy: Building and Running a Restaurant** * **Dockerfile** = *Recipe Book* β†’ Tells you how to cook a dish (build your app image). * **Image** = *Prepared Meal in a Box* β†’ The result of following the recipe. It’s ready to be served but not β€œeaten” yet. * **Container** = *Table where the meal is served* β†’ It runs the image (meal), isolated from other tables. Each container is like its own customer with its own plate. * **Docker Compose File** = *Restaurant Manager* β†’ Organizes many meals (services) and tells the kitchen when and how to cook and serve each dish. Manages multi-container apps. * **App** = *The dish itself* β†’ Your website, database, etc., running inside containers. * **Environment** = *Restaurant theme/config* β†’ Custom settings: e.g., lighting, music, menu (ENV variables like DB name, passwords, etc.) --- ## 🐳 vs πŸ–₯ **Docker vs Virtual Machine** | Feature | Docker (Container) | Virtual Machine (VM) | | -------------- | --------------------------------- | --------------------------------- | | Boot time | Seconds | Minutes | | Resource usage | Lightweight | Heavy (full OS) | | Isolation | Shares OS kernel | Full OS isolation | | Use case | Run apps in isolated environments | Full OS testing or legacy systems | **Analogy**: Docker is like using multiple apps in the same phone. VM is like giving every app its own phone. --- ## **What is Nginx?** **Nginx** (pronounced "engine-x") is a high-performance web server and reverse proxy server. It is widely used for serving static content, load balancing, handling high concurrency, and acting as a gateway to backend applications. **Why Use It:** * **High performance and scalability** – Efficiently handles thousands of simultaneous connections. * **Load balancing** – Distributes traffic across multiple servers. * **Reverse proxying** – Secures and accelerates backend services. * **Static file serving** – Excellent for serving HTML, CSS, JS, and media content. * **Resource efficiency** – Low memory usage compared to alternatives like Apache. --- ## **What is WordPress?** **WordPress** is a free and open-source content management system (CMS) primarily used to create and manage websites and blogs. It is built on PHP and uses MySQL for data storage. **Why Use It:** * **User-friendly interface** – No coding skills needed for basic use. * **Customizability** – Thousands of themes and plugins. * **Large community and support** – Extensive documentation and forums. * **SEO-friendly** – Built-in and plugin-based optimization tools. * **Flexible use cases** – From blogs and portfolios to e-commerce and enterprise sites. --- ## πŸ›’ **What is MariaDB?** * MariaDB is an **open-source database server**, a drop-in replacement for MySQL. * It **stores structured data** β€” like WordPress posts, users, comments. * Think of it as the **digital filing cabinet** for your application. --- ## πŸ’Ύ **What Is Volume?** #### πŸ”Έ A Volume is like an **external hard drive** connected to your container. #### βœ… **Purpose**: * Store data **persistently** (so it survives even if the container is deleted). * Separate **app logic** from **app data**. #### 🧱 **Relation to directories**: * You mount volumes to specific folders in the container (e.g., `/var/lib/mysql` for MariaDB). #### πŸ“Œ Volume Usage Examples: * **MariaDB**: volume stores the database files. * Without a volume: database is deleted when the container stops. * **WordPress**: volume stores uploads, themes, plugins. --- ## ⚑ **[BONUS] What Is Redis?** * Redis is an **in-memory key-value store** (NoSQL). * Commonly used as: * A **cache** (speed up WordPress) * A **session store** (store user login sessions) > Imagine it as a **super-fast notebook** your app can use for temporary, frequently-accessed data. --- ## πŸ“‹ **[BOUNS] What Is Adminer?** * **Adminer** is a lightweight web-based **database management tool**. * Think of it like **phpMyAdmin**, but simpler and faster. * You use it to: * Log into your database * View tables * Run SQL commands * Debug your WordPress DB setup > It connects directly to MariaDB to help manage your data visually.