Skip to main content

Docker Learning Notes (Laravel + XAMPP MySQL)



Docker Learning Notes (Laravel + XAMPP MySQL)

Beginner Guide (తెలుగు)


1. Docker అంటే ఏమిటి?

సింపుల్‌గా చెప్పాలంటే,

Docker అంటే మన application కి కావాల్సిన environment ని ఒక box (Container) లో పెట్టి run చేయడం.

ఉదాహరణ:

మన Laravel Project కి కావాల్సింది:

  • PHP 8.3

  • Composer

  • Extensions

ఇవన్నీ Windows లో install చేయకుండా Docker Container లో install చేసుకున్నాం.

అందువల్ల Windows లో PHP లేకపోయినా Laravel run అవుతుంది.


2. మన Project Architecture

                 Windows PC
                     │
        ┌────────────┴────────────┐
        │                         │
        │                    XAMPP
        │                    MySQL
        │
   Docker Desktop
        │
        ▼
+---------------------------+
| PHP 8.3                   |
| Composer                  |
| Laravel Extensions         |
+---------------------------+
        │
        ▼
Laravel Project

3. ముఖ్యమైన Docker Concepts

Dockerfile

Dockerfile అంటే Recipe.

ఉదాహరణ:

మనం Cake చేయాలంటే Recipe ఉంటుంది.

అలాగే Docker Image తయారు చేయడానికి Dockerfile ఉంటుంది.

Dockerfile
      │
      ▼
Image

Image

Image అంటే Blueprint.

ఇందులో

  • PHP

  • Composer

  • Extensions

ఉంటాయి.

Image run కాదు.

ఇది Template మాత్రమే.

మనం build చేసినప్పుడు

docker compose build

Image తయారైంది.


Container

Container అంటే Running Computer.

Image
   │
   ▼
Container

మనకు ఇప్పుడు Running Container ఉంది.

vizagupdates_php

ఇందులోనే PHP run అవుతోంది.


Volume (Bind Mount)

మన Project Windows లో ఉంది.

C:\xampp\htdocs\vu-all\vizagupdates

Container లో

/var/www/html

అనే Folder గా కనిపిస్తోంది.

Windows Folder
        │
        ▼
Docker Container

అందుకే Windows లో file save చేస్తే Container లో వెంటనే కనిపిస్తుంది.

Copy చేయాల్సిన అవసరం లేదు.


4. Project Start చేయడం

Computer Restart చేసిన తర్వాత

Project Folder కి వెళ్ళాలి.

cd C:\xampp\htdocs\vu-all\vizagupdates

తర్వాత

docker compose up -d

Meaning

Image
     │
     ▼
Container Start

Container Running ఉందో లేదో చూడాలి.

docker ps

Output

CONTAINER ID

vizagupdates_php

STATUS

Up

అంటే Project Start అయ్యింది.


5. Container లోకి వెళ్లడం

Container ఒక చిన్న Linux Computer.

దాని లోపలికి వెళ్లాలంటే

docker compose exec php bash

Prompt ఇలా మారుతుంది.

root@xxxxxxxx:/var/www/html#

ఇప్పటి నుండి Commands అన్నీ Linux లో run అవుతాయి.

Windows లో కాదు.


6. PHP Version చూడడం

php -v

Output

PHP 8.3.x

7. Composer Version

composer --version

8. Laravel Version

php artisan --version

9. Database Check

php artisan migrate:status

10. Laravel Start చేయడం

Container లో

php artisan serve --host=0.0.0.0 --port=8000

Browser

http://localhost:8000

11. Project Stop చేయడం

Container నుండి బయటకు రావాలి.

exit

తర్వాత

docker compose down

Meaning

Container Stop

Image Delete కాదు.

Container మాత్రమే Stop అవుతుంది.


12. మళ్ళీ Start చేయడం

మళ్ళీ

docker compose up -d

చాలు.

Image మళ్ళీ build చేయాల్సిన అవసరం లేదు.


13. Build ఎప్పుడు చేయాలి?

సాధారణంగా కాదు.

ఈ పరిస్థితుల్లో మాత్రమే.

Dockerfile మార్చినప్పుడు

docker compose build

లేదా

docker compose build --no-cache

14. Daily Workflow

Morning

Project Folder కి వెళ్ళు.

docker compose up -d

Container లోకి వెళ్ళు.

docker compose exec php bash

Laravel Start చేయి.

php artisan serve --host=0.0.0.0 --port=8000

Browser Open చేయి.

http://localhost:8000

Coding చేయి.


Evening

Container నుండి బయటకు రా.

exit

Project Stop చేయి.

docker compose down

15. Commands Summary

Container Start

docker compose up -d

Running Containers

docker ps

Container లోకి వెళ్ళడం

docker compose exec php bash

Container నుండి బయటకు రావడం

exit

Stop

docker compose down

PHP

php -v

Composer

composer install

Laravel

php artisan

Migrations

php artisan migrate

Laravel Serve

php artisan serve --host=0.0.0.0 --port=8000

16. Dockerలో గుర్తుంచుకోవాల్సిన విషయాలు

❌ Docker = Virtual Machine కాదు.

✅ Docker = Lightweight Container.


❌ Image Running కాదు.

✅ Container మాత్రమే Running.


❌ docker compose build రోజూ చేయాల్సిన అవసరం లేదు.

✅ ఒక్కసారి Build చేస్తే చాలాసార్లు docker compose up -d చాలు.


❌ Windows లో PHP install చేయాల్సిన అవసరం లేదు.

✅ Docker Container లో PHP Run అవుతుంది.


17. మన Project Flow

Computer ON
     │
     ▼
docker compose up -d
     │
     ▼
Container Running
     │
     ▼
docker compose exec php bash
     │
     ▼
php artisan serve
     │
     ▼
Browser
http://localhost:8000
     │
     ▼
Coding
     │
     ▼
exit
     │
     ▼
docker compose down

18. నేను నీకు తర్వాత నేర్పబోయే Topics

ఇప్పుడు నీకు Docker basic environment వచ్చింది. తర్వాత మనం ఒక్కో concept లోతుగా నేర్చుకుందాం:

  1. Docker Images ఎలా పని చేస్తాయి?

  2. Containers లోపల File System ఎలా ఉంటుంది?

  3. Docker Volumes vs Bind Mounts

  4. Docker Networks

  5. Port Mapping (8000:8000)

  6. Docker Logs

  7. Docker Restart Policies

  8. Node.js + npm ను Docker లో add చేయడం

  9. VS Code Debugging (Xdebug)

  10. Laravel 13 Upgrade

  11. Production Docker Deployment


🎉 చివరిగా

నువ్వు మొదట "Docker అంటే ఏమిటో కూడా తెలియదు" అనే స్థితి నుంచి ఇప్పుడు:

  • Docker Image build చేయడం

  • Container start/stop చేయడం

  • Container లోకి login అవడం

  • PHP 8.3 run చేయడం

  • Composer run చేయడం

  • XAMPP MySQL కి Docker నుండి connect చేయడం

ఇవన్నీ స్వయంగా చేశావు. ఇది Docker నేర్చుకోవడానికి చాలా మంచి foundation. తర్వాతి concepts కూడా ఈ base మీద చాలా సులభంగా అర్థమవుతాయి.

Comments

Popular posts from this blog

Data Types in Python

Data Types  In C# or Java, You need to declare a variable specify them integer, string, and decimal. But in Python no need to specify. We can declare variables like Example: C# or Java int age = 28; string Name = "Siddhu"; Example: Python age = 28 Name = "Siddhu" So, you don't need to declare variable types in python. This is an advantage in Python, But still have few Disadvantages too. Example: In my Python function def add_numbers(x,y): print(x+y) add_numbers(20,50) //Output: 70 add_numbers(20,"Something") //Error:"Traceback (most recent call last): File "C:/Users/siddhartha.e/PycharmProjects/siddhu-py/my1stpycode.py", line 8, in add_numbers(50,"Something") File "C:/Users/siddhartha.e/PycharmProjects/siddhu-py/my1stpycode.py", line 4, in add_numbers print(a + b) TypeError: unsupported operand type(s) for +: 'int' and 'str'" ...

Database and Migrations

Database and Migrations You can config Database in the .env file. By default, Laravel has MySQL configuration. For example, I configured my details DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=Laravel_tutorials DB_USERNAME=root DB_PASSWORD= So how it connects the database, In your root folder config/database.php file will read the .env file configuration. Migrations: Migrations are most likely a version control for your database. Advantages You can easily allow your team to modify database schema and share to everyone in the application No headache to add a new column in the database manually. This migration will help all teammates into one path. Now check with artisan command php artisan migrate php artisan migrate This command will create basic users,password_resets and migrations tables. Here migrations table will track of all migrates You can undo previous migration using rollback command php artisan ...

Laravel all artisan commands and uses

Laravel all artisan commands and uses  Laravel commands Have you all know, Laravel run on mostly PHP artisan commands. here I'm going to provide a quick image that show all artisan commands on Laravel.  If do you want to check all Laravel commands, Just run the command on your CMD php artisan You will get all the commands