395
195 shares, 395 points

Docker คืออะไร?

Docker เป็นแพลตฟอร์มสำหรับสร้าง จัดการ และรันแอปพลิเคชันผ่านคอนเทนเนอร์ (Container) ซึ่งช่วยให้สามารถพัฒนาและใช้งานซอฟต์แวร์ได้อย่างรวดเร็วและมีประสิทธิภาพ

ติดตั้ง Docker

บน Windows

  1. ดาวน์โหลด Docker Desktop จาก Docker Official
  2. ติดตั้งโดยทำตามขั้นตอนที่กำหนด
  3. เปิด Docker Desktop และตรวจสอบว่าทำงานได้โดยใช้คำสั่งdocker version

บน macOS

  1. ดาวน์โหลด Docker Desktop for Mac จากลิงก์เดียวกัน
  2. ติดตั้งและเปิดใช้งาน
  3. ตรวจสอบเวอร์ชันdocker version

บน Linux (Ubuntu 20.04+)

ติดตั้งแพ็กเกจที่จำเป็น

sudo apt update sudo apt install ca-certificates curl gnupg

เพิ่ม GPG Key และ Repository

sudo install -m 0755 -d /etc/apt/keyrings 
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg  sudo tee /etc/apt/keyrings/docker.asc > /dev/null  sudo chmod a+r /etc/apt/keyrings/docker.asc

ติดตั้ง Docker

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null  sudo apt update  sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

ตรวจสอบการติดตั้ง

docker version

คำสั่งพื้นฐานของ Docker

ตรวจสอบเวอร์ชันของ Docker

docker --version

ดึง (Pull) ภาพของ Container

docker pull nginx

รัน Container

docker run -d -p 8080:80 --name my-nginx nginx
  • -d รันแบบ background
  • -p 8080:80 แมปพอร์ตจากเครื่องเรา (8080) ไปยัง Container (80)
  • --name my-nginx กำหนดชื่อ Container

ดูรายการ Container ที่กำลังทำงานอยู่

docker ps

หยุด Container

docker stop my-nginx

ลบ Container

docker rm my-nginx

ใช้งาน Docker กับ Laravel

ถ้าใช้งาน Laravel สามารถใช้ Docker ผ่าน sail ได้

ดึง Laravel มาใช้งาน

curl -s https://laravel.build/example-app | bash

เข้าไปที่โฟลเดอร์โปรเจกต์

cd example-app

รัน Laravel ด้วย Docker

./vendor/bin/sail up -d

สรุป

Docker ช่วยให้การพัฒนาแอปพลิเคชันง่ายขึ้นโดยไม่ต้องติดตั้งซอฟต์แวร์ซ้ำๆ บนเครื่องหลัก และสามารถใช้ร่วมกับ Laravel ได้ง่ายผ่าน sail


Like it? Share with your friends!

395
195 shares, 395 points

What's Your Reaction?

รัก รัก
166
รัก
หัวเราะ หัวเราะ
1666
หัวเราะ
โกรธ โกรธ
1500
โกรธ
ว้าว ว้าว
1333
ว้าว
ร้องไห้ ร้องไห้
1166
ร้องไห้
ชอบ ชอบ
1000
ชอบ
ไม่ชอบ ไม่ชอบ
833
ไม่ชอบ
ADMIN

Wood 9

0 Comments

อีเมลของคุณจะไม่แสดงให้คนอื่นเห็น ช่องข้อมูลจำเป็นถูกทำเครื่องหมาย *

Choose A Format
Personality quiz
Series of questions that intends to reveal something about the personality
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Poll
Voting to make decisions or determine opinions
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Countdown
The Classic Internet Countdowns
Open List
Submit your own item and vote up for the best submission
Ranked List
Upvote or downvote to decide the best list item
Meme
Upload your own images to make custom memes
Video
Youtube and Vimeo Embeds
Audio
Soundcloud or Mixcloud Embeds
Image
Photo or GIF
Gif
GIF format