1 · Words 2 · Machines 3 · Install 4 · React site 5 · Share it 6 · Docker Hub 7 · Kubernetes

🐳 Docker Lab

A program needs many things to run. It needs the right computer language. It needs the right helper files. It needs the right settings. On your computer it works. On my computer it does not. This is an old problem. Docker puts the program and all its things in one box. The box runs the same way on every computer. 一个程序要跑起来,需要很多东西:合适的语言、合适的辅助文件、合适的设置。 在你的电脑上能跑,在我的电脑上却不行——这是个老问题。Docker 把程序和它需要的所有东西装进一个盒子。 这个盒子在每台电脑上跑起来都一样。 โปรแกรมหนึ่งตัวต้องใช้หลายอย่างจึงจะทำงานได้ ต้องมีภาษาที่ถูก ต้องมีไฟล์ช่วยที่ถูก ต้องมีการตั้งค่าที่ถูก บนเครื่องคุณมันทำงาน บนเครื่องผมมันไม่ทำงาน นี่คือปัญหาเก่า Docker เอาโปรแกรมและทุกอย่างที่มันต้องใช้ ใส่ลงในกล่องเดียว กล่องนี้ทำงานเหมือนกันทุกเครื่อง

Today you will do six things. You will learn the words. You will drive four small machines. You will put Docker on your computer. You will build a React web site inside a box. You will show it to the world with Tailscale. You will send your box to Docker Hub. At the end we look at Kubernetes. 今天你会做六件事:学词、玩四台小机器、在电脑上装 Docker、在盒子里做一个 React 网站、 用 Tailscale 把它分享给全世界、把盒子推送到 Docker Hub。最后我们看看 Kubernetes。 วันนี้คุณจะทำหกอย่าง เรียนคำศัพท์ เล่นเครื่องมือเล็ก ๆ สี่ตัว ติดตั้ง Docker บนเครื่องของคุณ สร้างเว็บไซต์ React ในกล่อง แชร์ให้คนทั้งโลกดูด้วย Tailscale และส่งกล่องขึ้น Docker Hub ตอนท้ายเราจะดู Kubernetes

You need three things. A computer with Windows 10/11 or a Mac. About 10 GB of free disk space. An internet connection. You do not need to pay money. 你需要三样东西:一台 Windows 10/11 电脑或 Mac;大约 10 GB 空闲硬盘空间;网络连接。 不需要花钱。 คุณต้องมีสามอย่าง คอมพิวเตอร์ Windows 10/11 หรือ Mac พื้นที่ว่างประมาณ 10 GB และอินเทอร์เน็ต ไม่ต้องเสียเงิน

🔤 The words you need

Summary

Twenty-two words. Every word here is a real Docker word. You will type most of them today. People all over the world say these words in English. So learning the words is learning the job. Tap say it to hear one word. Tap tell me more to read a long answer.

摘要

二十二个词。这里每个词都是真正的 Docker 用词,今天你几乎都会亲手敲一遍。全世界的人都用英语说这些词,所以学会这些词就是学会这份工作。点 say it 听发音,点 tell me more 读详细解释。

สรุป

ยี่สิบสองคำ ทุกคำเป็นคำ Docker จริง วันนี้คุณจะได้พิมพ์เกือบทุกคำ คนทั่วโลกพูดคำเหล่านี้เป็นภาษาอังกฤษ เรียนคำพวกนี้คือเรียนงานจริง แตะ say it เพื่อฟังหนึ่งคำ แตะ tell me more เพื่ออ่านคำอธิบายยาว

🔧 Four little machines

Each machine shows a real Docker command on the left. It shows the real picture on the right. Move the slider. Press the button. The command you see is the command that made the picture. 每台机器左边是真正的 Docker 命令,右边是真正的图。拖滑块、按按钮。 你看到的命令就是画出这张图的命令。 แต่ละเครื่องแสดงคำสั่ง Docker จริงทางซ้าย และรูปจริงทางขวา เลื่อนแถบ กดปุ่ม คำสั่งที่คุณเห็นคือคำสั่งที่ทำให้เกิดรูปนั้น

📦 1 · One image, many containers

Summary

An image is a cold box. It does not run. It only sits on the disk. A container is a hot box. It runs. You make a container from an image with docker run. One image can make many containers. Press run again and again and watch them appear.

摘要

镜像是一个冷盒子,它不运行,只是躺在硬盘上。容器是一个热盒子,它在运行。用 docker run 从镜像做出容器。一个镜像可以做出很多容器。多按几次 run,看它们出现。

สรุป

อิมเมจคือกล่องเย็น มันไม่ทำงาน มันแค่นอนอยู่บนดิสก์ คอนเทนเนอร์คือกล่องร้อน มันทำงาน คุณสร้างคอนเทนเนอร์จากอิมเมจด้วย docker run อิมเมจหนึ่งตัวสร้างคอนเทนเนอร์ได้หลายตัว กดปุ่ม run ซ้ำ ๆ แล้วดูมันโผล่ขึ้นมา

# the cold box on your disk docker images # my-site 1.0 48 MB # make a hot box from it docker run -d -p 8080:80 my-site # running now: 0
Why many? The image never changes. Each container gets its own memory and its own port. If one container breaks, you delete it and run a new one. The image is still clean. 为什么可以很多个?镜像永远不变。每个容器有自己的内存和自己的端口。 一个容器坏了,删掉它再 run 一个新的,镜像还是干净的。 ทำไมได้หลายตัว? อิมเมจไม่เคยเปลี่ยน คอนเทนเนอร์แต่ละตัวมีหน่วยความจำและพอร์ตของตัวเอง ถ้าตัวไหนพัง ลบทิ้งแล้วสั่ง run ใหม่ อิมเมจยังสะอาดเหมือนเดิม
0 containers running

💾 Put Docker on your computer

Summary

Docker Desktop is free for one person. It is free for a small company. It is free for a school. Pick your computer below. Windows needs one extra step first. It needs WSL. A Mac does not need that step. Both take about fifteen minutes.

摘要

Docker Desktop 对个人免费,对小公司免费,对学校免费。在下面选你的电脑。Windows 要先多做一步:安装 WSL。Mac 不需要这一步。两种都大约要十五分钟。

สรุป

Docker Desktop ฟรีสำหรับคนคนเดียว ฟรีสำหรับบริษัทเล็ก ฟรีสำหรับโรงเรียน เลือกเครื่องของคุณข้างล่าง Windows ต้องทำเพิ่มหนึ่งขั้นตอนก่อน คือ WSL ส่วน Mac ไม่ต้อง ทั้งสองแบบใช้เวลาประมาณสิบห้านาที

1 Check your Windows

Press the Windows key and R together. Type winver. Press Enter. You need Windows 10 or Windows 11. You need the 64-bit kind. 同时按 Windows 键和 R,输入 winver,按回车。 你需要 Windows 10 或 Windows 11,并且是 64 位的。 กด Windows พร้อม R พิมพ์ winver แล้วกด Enter คุณต้องใช้ Windows 10 หรือ Windows 11 แบบ 64 บิต

2 Turn on WSL

WSL lets Windows run Linux inside it. Docker needs this. Right-click the Start button. Choose Terminal (Admin). Say yes. Then type this one line. WSL 让 Windows 在里面跑 Linux,Docker 需要它。右键点开始按钮,选 终端(管理员),点“是”。然后输入这一行。 WSL ทำให้ Windows รัน Linux ข้างในได้ Docker ต้องใช้สิ่งนี้ คลิกขวาที่ปุ่ม Start เลือก Terminal (Admin) แล้วกดยืนยัน จากนั้นพิมพ์บรรทัดนี้

wsl --install

Wait. It takes some minutes. Then restart your computer. This step is only once, for ever. 等几分钟,然后重启电脑。这一步一辈子只做一次。 รอสักครู่ ใช้เวลาหลายนาที แล้วรีสตาร์ทเครื่อง ขั้นตอนนี้ทำครั้งเดียวตลอดไป

3 Download Docker Desktop

Go to docker.com/products/docker-desktop. Click Download for Windows. Pick AMD64 for a normal PC. The file is big, about 600 MB. 打开 docker.com/products/docker-desktop,点 Download for Windows。 普通电脑选 AMD64。文件很大,大约 600 MB。 ไปที่ docker.com/products/docker-desktop กด Download for Windows เครื่องพีซีทั่วไปให้เลือก AMD64 ไฟล์ใหญ่ประมาณ 600 MB

4 Install it

Double-click the file. Keep the box Use WSL 2 instead of Hyper-V ticked. Click OK. Wait. When it finishes, restart again. 双击文件。保持勾选 Use WSL 2 instead of Hyper-V,点 OK。 等它装完,再重启一次。 ดับเบิลคลิกไฟล์ ให้ติ๊กช่อง Use WSL 2 instead of Hyper-V ไว้ กด OK รอจนเสร็จ แล้วรีสตาร์ทอีกครั้ง

5 Open Docker Desktop

Open it from the Start menu. Accept the terms. You can skip the sign-in now. Look at the little whale at the bottom left. Wait until it stops moving and turns green. Green means Docker is ready. 从开始菜单打开它,接受条款,现在可以跳过登录。看左下角那只小鲸鱼, 等它不动了并变成绿色,绿色就表示 Docker 准备好了。 เปิดจากเมนู Start กดยอมรับเงื่อนไข ตอนนี้ข้ามการล็อกอินไปก่อนได้ ดูรูปวาฬเล็ก ๆ มุมล่างซ้าย รอจนมันหยุดขยับและเปลี่ยนเป็นสีเขียว สีเขียวแปลว่า Docker พร้อมแล้ว

6 Test it

Open PowerShell from the Start menu. Type this. 从开始菜单打开 PowerShell,输入这个。 เปิด PowerShell จากเมนู Start แล้วพิมพ์แบบนี้

docker run hello-world

What good looks like

Docker cannot find hello-world on your computer. So it gets it from the internet. Then it runs it. You see this: Docker 在你电脑上找不到 hello-world,就去网上取,然后运行它。你会看到这个: Docker หาไฟล์ hello-world ในเครื่องคุณไม่เจอ จึงไปดึงจากอินเทอร์เน็ต แล้วรันมัน คุณจะเห็นแบบนี้

Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly.
If it says "cannot connect to the Docker daemon". Docker Desktop is not running. Open the app and wait for green. Then try again. This is the most common first problem, and it is not a bug. 如果提示 "cannot connect to the Docker daemon":Docker Desktop 没在运行。 打开这个应用,等它变绿,再试一次。这是最常见的第一个问题,不是 bug。 ถ้าขึ้นว่า "cannot connect to the Docker daemon" แปลว่า Docker Desktop ยังไม่ทำงาน ให้เปิดแอปแล้วรอจนเป็นสีเขียว จากนั้นลองใหม่ นี่คือปัญหาแรกที่พบบ่อยที่สุด และไม่ใช่บั๊ก

⚛️ Build a React web site in a box

Summary

React is a tool for making web pages. React needs Node. But you will not install Node. Docker will give you Node inside a box. You make the site, you write a Dockerfile, you build an image, and you run it. Nine steps. Type every line yourself.

摘要

React 是做网页的工具,React 需要 Node。但你不用装 Node,Docker 会在盒子里给你 Node。你先做出网站,再写一个 Dockerfile,然后构建镜像并运行它。一共九步,每一行都自己敲。

สรุป

React คือเครื่องมือสำหรับทำหน้าเว็บ React ต้องใช้ Node แต่คุณจะไม่ติดตั้ง Node เพราะ Docker จะให้ Node ในกล่องแทน คุณสร้างเว็บ เขียน Dockerfile สร้างอิมเมจ แล้วรันมัน เก้าขั้นตอน พิมพ์เองทุกบรรทัด

Open your terminal first. On Windows that is PowerShell. On a Mac that is Terminal. Some commands are a little different on the two computers. Where they are different, both lines are in the box. 先打开终端:Windows 上是 PowerShell,Mac 上是 Terminal。 有些命令在两种电脑上略有不同,不同的地方两行都写在框里。 เปิดเทอร์มินัลก่อน บน Windows คือ PowerShell บน Mac คือ Terminal บางคำสั่งต่างกันเล็กน้อยระหว่างสองเครื่อง ตรงที่ต่างกันจะใส่ทั้งสองบรรทัดไว้ในกล่อง

1 Make a folder

Make a new folder. Go inside it. This works the same on both computers. 新建一个文件夹,进去。两种电脑都一样。 สร้างโฟลเดอร์ใหม่ แล้วเข้าไปข้างใน ทั้งสองเครื่องเหมือนกัน

mkdir my-site cd my-site

2 Make the React app — with no Node on your computer

This is the first magic. The command below starts a box with Node inside. The box uses your folder. It makes the React files. Then the box goes away. Your computer stays clean. 这是第一个魔法:下面的命令启动一个装着 Node 的盒子,盒子使用你的文件夹, 造出 React 文件,然后盒子就消失了。你的电脑还是干干净净。 นี่คือเวทมนตร์อย่างแรก คำสั่งข้างล่างเปิดกล่องที่มี Node อยู่ข้างใน กล่องใช้โฟลเดอร์ของคุณ สร้างไฟล์ React ให้ แล้วกล่องก็หายไป เครื่องของคุณยังสะอาดเหมือนเดิม

# Mac / Linux docker run --rm -it -v "$PWD":/app -w /app node:20-alpine npm create vite@latest app # Windows PowerShell docker run --rm -it -v "${PWD}:/app" -w /app node:20-alpine npm create vite@latest app

It asks two questions. For the framework, choose React. For the variant, choose JavaScript. Use the arrow keys. Press Enter. 它会问两个问题:框架选 React,变体选 JavaScript。用方向键选,按回车。 มันจะถามสองคำถาม เฟรมเวิร์กให้เลือก React แบบย่อยให้เลือก JavaScript ใช้ปุ่มลูกศรเลือก แล้วกด Enter

Read the flags. --rm means throw the box away after. -it means let me answer questions. -v means share this folder with the box. -w means start in that folder. You will use these four for ever. 读懂这些参数:--rm 用完就扔掉盒子;-it 让我能回答问题; -v 把这个文件夹分享给盒子;-w 从那个文件夹开始。这四个你会用一辈子。 อ่านแฟล็กให้เข้าใจ --rm คือทิ้งกล่องหลังใช้เสร็จ -it คือให้ฉันตอบคำถามได้ -v คือแชร์โฟลเดอร์นี้ให้กล่อง -w คือเริ่มที่โฟลเดอร์นั้น สี่ตัวนี้คุณจะใช้ไปตลอด

Now go into the new folder. 现在进入新文件夹。 ตอนนี้เข้าไปในโฟลเดอร์ใหม่

cd app

3 Look at what you got

app/ ├── index.html the first page ├── package.json the list of helper programs ├── vite.config.js settings └── src/ ├── main.jsx the start line └── App.jsx your page — you will edit this one

There is no node_modules folder yet. That is fine. Docker will make it. 现在还没有 node_modules 文件夹,没关系,Docker 会造出来。 ตอนนี้ยังไม่มีโฟลเดอร์ node_modules ไม่เป็นไร Docker จะสร้างให้

4 Write your own page

Open src/App.jsx in any text editor. Delete everything. Put this in. 用任何文本编辑器打开 src/App.jsx,全部删掉,换成这个。 เปิด src/App.jsx ด้วยโปรแกรมแก้ข้อความอะไรก็ได้ ลบทั้งหมด แล้วใส่อันนี้

import { useState } from "react"; export default function App() { const [count, setCount] = useState(0); return ( <div style={{ fontFamily: "sans-serif", padding: "3rem" }}> <h1>Hello from Chiang Mai 🌤️</h1> <p>This page lives in a Docker box.</p> <button onClick={() => setCount(count + 1)}> I pressed it {count} times </button> </div> ); }

5 Write the Dockerfile

A Dockerfile is a recipe. Docker reads it from the top to the bottom. Make a new file called Dockerfile. No dot, no ending. Put this in it. Dockerfile 是一份食谱,Docker 从上往下读。 新建一个文件叫 Dockerfile,没有点,没有后缀名。写入这些。 Dockerfile คือสูตรอาหาร Docker อ่านจากบนลงล่าง สร้างไฟล์ใหม่ชื่อ Dockerfile ไม่มีจุด ไม่มีนามสกุล แล้วใส่สิ่งนี้ลงไป

# ── Part 1: build the site ── FROM node:20-alpine AS build WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build # ── Part 2: serve the site ── FROM nginx:alpine COPY --from=build /app/dist /usr/share/nginx/html EXPOSE 80
Why two parts? Part 1 needs Node. Node is big: about 400 MB. But the finished site is only some small files. Part 2 starts again with a tiny web server and copies only those files. Your image ends up about 50 MB, not 400 MB. This is called a multi-stage build. 为什么分两部分?第一部分需要 Node,Node 很大,大约 400 MB; 但做好的网站只是几个小文件。第二部分从一个很小的网页服务器重新开始,只复制那些文件。 最后镜像大约 50 MB,不是 400 MB。这叫多阶段构建 ทำไมต้องสองส่วน? ส่วนแรกต้องใช้ Node ซึ่งใหญ่ประมาณ 400 MB แต่เว็บที่สร้างเสร็จเป็นแค่ไฟล์เล็ก ๆ ไม่กี่ไฟล์ ส่วนที่สองเริ่มใหม่ด้วยเว็บเซิร์ฟเวอร์ตัวจิ๋ว และคัดลอกเฉพาะไฟล์เหล่านั้น อิมเมจสุดท้ายจึงประมาณ 50 MB ไม่ใช่ 400 MB เรียกว่า multi-stage build

6 Write a .dockerignore

Make a file called .dockerignore. It tells Docker what to leave out. This makes the build much faster. 新建一个文件 .dockerignore,告诉 Docker 哪些东西不要带进去,构建会快很多。 สร้างไฟล์ชื่อ .dockerignore บอก Docker ว่าไม่ต้องเอาอะไรเข้าไป จะทำให้ build เร็วขึ้นมาก

node_modules dist .git Dockerfile

7 Build the image

Now cook the recipe. The dot at the end means "the recipe is in this folder". Do not forget the dot. 现在开始做这道菜。末尾的点表示“食谱在这个文件夹里”。别忘了那个点。 ตอนนี้ลงมือทำตามสูตร จุดท้ายสุดแปลว่า "สูตรอยู่ในโฟลเดอร์นี้" อย่าลืมจุด

docker build -t my-site:1.0 .

The first time is slow. Two or three minutes. The second time is fast, because of the cache you saw in machine 3. 第一次比较慢,两三分钟;第二次很快,因为有你在第三台机器里看到的缓存。 ครั้งแรกช้า สองถึงสามนาที ครั้งที่สองเร็วมาก เพราะมีแคชอย่างที่คุณเห็นในเครื่องที่ 3

docker images # REPOSITORY TAG IMAGE ID SIZE # my-site 1.0 9f2c1a4b8e01 52.3MB

8 Run it

docker run -d -p 8080:80 --name web my-site:1.0

Open your browser. Go to http://localhost:8080. Your site is there. Press the button. It counts. 打开浏览器,访问 http://localhost:8080,你的网站就在那里。按那个按钮,它会计数。 เปิดเบราว์เซอร์ ไปที่ http://localhost:8080 เว็บของคุณอยู่ตรงนั้น กดปุ่มดู มันจะนับให้

What is -d? It means "run in the background". Without it, the terminal is stuck until you press Ctrl+C. -d 是什么?意思是“在后台运行”。不加它,终端会卡住, 直到你按 Ctrl+C -d คืออะไร? แปลว่า "รันเบื้องหลัง" ถ้าไม่ใส่ เทอร์มินัลจะค้างจนกว่าคุณจะกด Ctrl+C

9 Five commands you will use every day

docker ps # what is running now docker logs web # what did it say docker stop web # stop it docker start web # start it again docker rm -f web # delete the container

The image is still there after you delete the container. Run step 8 again and you get a new one in one second. 删掉容器后镜像还在。再跑一次第 8 步,一秒钟就有一个新的。 หลังลบคอนเทนเนอร์แล้ว อิมเมจยังอยู่ ทำขั้นที่ 8 ซ้ำ คุณจะได้ตัวใหม่ในหนึ่งวินาที

Extra — see your changes while you type. The image above is finished and fixed. While you are still writing code, use this instead. It watches your files. Save a file, and the browser changes by itself. Open http://localhost:5173. 附加 —— 边写边看变化。上面的镜像是做好、固定的。你还在写代码的时候,用下面这个: 它会盯着你的文件,保存文件后浏览器自己就变了。打开 http://localhost:5173 เสริม — เห็นการเปลี่ยนแปลงขณะพิมพ์ อิมเมจข้างบนเสร็จแล้วและตายตัว ระหว่างที่คุณยังเขียนโค้ดอยู่ ให้ใช้อันนี้แทน มันจะเฝ้าดูไฟล์ของคุณ พอบันทึกไฟล์ เบราว์เซอร์จะเปลี่ยนเอง เปิด http://localhost:5173
# Mac / Linux docker run --rm -it -v "$PWD":/app -w /app -p 5173:5173 node:20-alpine sh -c "npm install && npm run dev -- --host" # Windows PowerShell docker run --rm -it -v "${PWD}:/app" -w /app -p 5173:5173 node:20-alpine sh -c "npm install; npm run dev -- --host"

🌏 Show your site to the world with Tailscale

Summary

Your site is on localhost. Only you can see it. Your friend in Bangkok cannot. Tailscale makes a safe road to your computer. First you share the site with your own devices. Then, with one more word, you share it with the whole internet. You do not need to open your router. You do not need to pay.

摘要

你的网站在 localhost 上,只有你能看到,曼谷的朋友看不到。Tailscale 会修一条安全的路通到你的电脑。先分享给你自己的设备,再多加一个词,就能分享给整个互联网。不用动路由器,也不用花钱。

สรุป

เว็บของคุณอยู่บน localhost มีแค่คุณที่เห็น เพื่อนที่กรุงเทพฯ เห็นไม่ได้ Tailscale จะสร้างถนนปลอดภัยมาที่เครื่องคุณ ก่อนอื่นแชร์ให้อุปกรณ์ของคุณเอง แล้วเพิ่มอีกคำเดียว ก็แชร์ให้ทั้งอินเทอร์เน็ตได้ ไม่ต้องแตะเราเตอร์ ไม่ต้องเสียเงิน

1 Make a free account

Go to tailscale.com. Click Get started. Sign in with Google, Microsoft or GitHub. The free plan is for one person, up to 100 devices. That is plenty. 打开 tailscale.com,点 Get started,用 Google、Microsoft 或 GitHub 登录。 免费方案适合一个人,最多 100 台设备,足够用了。 ไปที่ tailscale.com กด Get started ล็อกอินด้วย Google, Microsoft หรือ GitHub แผนฟรีสำหรับหนึ่งคน ได้ถึง 100 อุปกรณ์ เหลือเฟือ

2 Install Tailscale on your computer

Windows: download the installer from tailscale.com/download. Run it. A small icon appears near the clock. Click it. Log in.
Mac: get it from the same page, or type brew install --cask tailscale. Open it. Log in. Windows:从 tailscale.com/download 下载安装程序并运行,时钟旁会出现一个小图标, 点它并登录。
Mac:同一个页面下载,或输入 brew install --cask tailscale,打开并登录。
Windows: ดาวน์โหลดตัวติดตั้งจาก tailscale.com/download แล้วรัน จะมีไอคอนเล็ก ๆ ขึ้นข้างนาฬิกา คลิกแล้วล็อกอิน
Mac: โหลดจากหน้าเดียวกัน หรือพิมพ์ brew install --cask tailscale เปิดแล้วล็อกอิน

3 Check that it works

tailscale status

You see your computer and a name like my-laptop.tail1234.ts.net. That long name is now the address of your computer. Remember it. 你会看到你的电脑和一个像 my-laptop.tail1234.ts.net 的名字。 这个长名字现在就是你电脑的地址,记住它。 คุณจะเห็นเครื่องของคุณ และชื่อแบบ my-laptop.tail1234.ts.net ชื่อยาว ๆ นี้คือที่อยู่ของเครื่องคุณแล้ว จำไว้

4 Share it with your own devices — private

Your container is on port 8080. This one line puts it on the safe road. 你的容器在 8080 端口,这一行把它放到那条安全的路上。 คอนเทนเนอร์ของคุณอยู่ที่พอร์ต 8080 บรรทัดเดียวนี้เอามันขึ้นถนนปลอดภัย

tailscale serve --bg 8080

Now open https://my-laptop.tail1234.ts.net on your phone. Your phone needs Tailscale too, and the same login. Only your devices can see it. Nobody else can. 现在在手机上打开 https://my-laptop.tail1234.ts.net。 手机也要装 Tailscale 并用同一个账号登录。只有你的设备能看到,别人看不到。 ตอนนี้เปิด https://my-laptop.tail1234.ts.net บนมือถือ มือถือต้องมี Tailscale และล็อกอินบัญชีเดียวกัน มีแค่อุปกรณ์ของคุณที่เห็น คนอื่นไม่เห็น

5 Share it with everybody — public

Change one word. serve becomes funnel. 改一个词:serve 变成 funnel เปลี่ยนคำเดียว จาก serve เป็น funnel

tailscale funnel --bg 8080

The first time, Tailscale prints a web link. Open it. It asks you to turn Funnel on for this computer. Click yes. Then run the command again. 第一次运行时,Tailscale 会打印一个网页链接。打开它,它会问你是否为这台电脑打开 Funnel, 点“是”,然后再运行一次命令。 ครั้งแรก Tailscale จะพิมพ์ลิงก์เว็บออกมา เปิดลิงก์นั้น มันจะถามว่าจะเปิด Funnel ให้เครื่องนี้ไหม กดตกลง แล้วรันคำสั่งอีกครั้ง

tailscale funnel status # https://my-laptop.tail1234.ts.net (Funnel on) # |-- / proxy http://127.0.0.1:8080

Send that https:// address to anybody. It works on any phone, anywhere. It already has a real lock icon, because Tailscale gets the certificate for you. 把那个 https:// 地址发给任何人,任何地方的任何手机都能打开。 它已经有真正的锁图标,因为 Tailscale 帮你申请了证书。 ส่งที่อยู่ https:// นั้นให้ใครก็ได้ เปิดได้จากมือถือทุกเครื่องทุกที่ และมีรูปกุญแจจริงอยู่แล้ว เพราะ Tailscale ขอใบรับรองให้คุณ

6 Turn it off

tailscale serve reset

This stops both serve and funnel. 这会同时停掉 servefunnel คำสั่งนี้หยุดทั้ง serve และ funnel

Three things to know. One: your computer must stay on and awake. When you close the lid, the site stops. Two: Funnel is really public. Anyone with the link can open it. Do not put private files or passwords in the container. Three: Funnel is for small things. It is not for a big shop with many buyers. 三件要知道的事:一、你的电脑必须开着、不能睡眠,合上盖子网站就停了。 二、Funnel 是真的公开的,拿到链接的人都能打开,不要把私人文件或密码放进容器。 三、Funnel 适合小东西,不适合有很多买家的大商店。 สามเรื่องที่ต้องรู้ หนึ่ง เครื่องของคุณต้องเปิดอยู่และไม่หลับ ถ้าปิดฝาเว็บจะหยุด สอง Funnel เปิดสาธารณะจริง ๆ ใครมีลิงก์ก็เปิดได้ อย่าใส่ไฟล์ส่วนตัวหรือรหัสผ่านไว้ในคอนเทนเนอร์ สาม Funnel เหมาะกับของเล็ก ๆ ไม่เหมาะกับร้านใหญ่ที่มีลูกค้าจำนวนมาก

☁️ Put your box on Docker Hub

Summary

Docker Hub is a shop for images. It is free. You put your image there. Then any computer in the world can pull it and run it in one line. This is how you send your work to a friend, to a server, or to a school. Your Docker Hub name becomes part of your image name, so choose it well.

摘要

Docker Hub 是镜像的商店,免费。你把镜像放上去,世界上任何一台电脑都能一行命令拉下来运行。这就是你把作品交给朋友、交给服务器、交给学校的方式。你的 Docker Hub 用户名会成为镜像名字的一部分,所以要好好选。

สรุป

Docker Hub คือร้านค้าของอิมเมจ ใช้ฟรี คุณเอาอิมเมจไปวางไว้ แล้วคอมพิวเตอร์เครื่องไหนในโลกก็ดึงมารันได้ด้วยคำสั่งเดียว นี่คือวิธีส่งงานให้เพื่อน ให้เซิร์ฟเวอร์ หรือให้โรงเรียน ชื่อผู้ใช้ Docker Hub จะกลายเป็นส่วนหนึ่งของชื่ออิมเมจ เลือกให้ดี

1 Sign up

Go to hub.docker.com/signup. Pick a username. Use small letters and numbers only. People will see this name for years, so choose a good one. Give your email. Open the email and click the link. 打开 hub.docker.com/signup,选一个用户名,只用小写字母和数字。 这个名字别人会看很多年,好好选。填邮箱,打开邮件点确认链接。 ไปที่ hub.docker.com/signup เลือกชื่อผู้ใช้ ใช้ตัวพิมพ์เล็กกับตัวเลขเท่านั้น คนจะเห็นชื่อนี้ไปอีกหลายปี เลือกให้ดี ใส่อีเมล แล้วเปิดอีเมลกดลิงก์ยืนยัน

2 Make an access token

Do not use your real password in the terminal. Make a token instead. Click your picture at the top right → Account settingsPersonal access tokensGenerate new token. Give it Read & Write. Copy the long string. You see it one time only. 不要在终端里用真实密码,改用令牌。点右上角头像 → Account settingsPersonal access tokensGenerate new token,权限选 Read & Write, 复制那串长字符。它只显示一次。 อย่าใช้รหัสผ่านจริงในเทอร์มินัล ให้สร้างโทเคนแทน คลิกรูปมุมขวาบน → Account settingsPersonal access tokensGenerate new token ให้สิทธิ์ Read & Write คัดลอกข้อความยาว ๆ นั้นไว้ มันแสดงครั้งเดียวเท่านั้น

3 Log in from your terminal

docker login -u yourname

It asks for a password. Paste the token. Nothing appears while you paste. That is normal. Press Enter. You see Login Succeeded. 它会要密码,粘贴令牌。粘贴时屏幕上什么都不显示,这是正常的。按回车, 看到 Login Succeeded 就好了。 มันจะถามรหัสผ่าน ให้วางโทเคนลงไป ระหว่างวางจะไม่มีอะไรขึ้นบนจอ เป็นเรื่องปกติ กด Enter แล้วจะเห็นคำว่า Login Succeeded

4 Give the image its real name

An image on Docker Hub must be called yourname/thing:version. Your local image is only called my-site:1.0. So give it a second name. Docker Hub 上的镜像必须叫 用户名/名字:版本。 你本地的镜像只叫 my-site:1.0,所以给它再起一个名字。 อิมเมจบน Docker Hub ต้องชื่อ ชื่อคุณ/ของ:เวอร์ชัน อิมเมจในเครื่องคุณชื่อแค่ my-site:1.0 จึงต้องตั้งชื่อที่สองให้มัน

docker tag my-site:1.0 yourname/my-site:1.0
tag does not copy. It only adds a second name to the same image. Both names point at the same thing. Change yourname to your real Docker Hub name in every line below. tag 不会复制。它只是给同一个镜像加第二个名字,两个名字指向同一个东西。 下面每一行里的 yourname 都要换成你真正的 Docker Hub 用户名。 tag ไม่ได้คัดลอก มันแค่เพิ่มชื่อที่สองให้อิมเมจเดิม ทั้งสองชื่อชี้ไปที่ของชิ้นเดียวกัน เปลี่ยน yourname เป็นชื่อ Docker Hub จริงของคุณในทุกบรรทัดข้างล่าง

5 Push it

docker push yourname/my-site:1.0

You watch the layers go up one by one. When it finishes, open hub.docker.com/r/yourname/my-site in your browser. Your box is on the internet. Your project is checked in. 你会看到一层一层上传。传完后,在浏览器打开 hub.docker.com/r/yourname/my-site,你的盒子就在互联网上了,项目已经签入。 คุณจะเห็นเลเยอร์ทยอยอัปโหลดทีละชั้น เมื่อเสร็จแล้วเปิด hub.docker.com/r/yourname/my-site ในเบราว์เซอร์ กล่องของคุณอยู่บนอินเทอร์เน็ตแล้ว โปรเจกต์ของคุณถูกเช็กอินเรียบร้อย

6 Now anybody can run it

Send this one line to a friend. It works on their computer. They do not need your code. They do not need Node. They only need Docker. 把这一行发给朋友,在他电脑上就能跑。他不需要你的代码,不需要 Node,只需要 Docker。 ส่งบรรทัดนี้ให้เพื่อน มันทำงานบนเครื่องเขาได้เลย เขาไม่ต้องมีโค้ดของคุณ ไม่ต้องมี Node ต้องมีแค่ Docker

docker run -d -p 8080:80 yourname/my-site:1.0
Careful with public images. A free account gives you many public places and one private place. Public means everyone can read everything inside. Never build a password, an API key or a customer list into an image. Later, change the version number every time you push: 1.0, then 1.1, then 1.2. Do not always use latest — then nobody knows what is inside. 公开镜像要小心。免费账号给你很多公开仓库和一个私有仓库。 公开意味着所有人都能读到里面的一切。绝不要把密码、API 密钥或客户名单打进镜像。 以后每次推送都改版本号:1.01.11.2。 不要老是用 latest,那样谁也不知道里面装的是什么。 ระวังอิมเมจสาธารณะ บัญชีฟรีให้พื้นที่สาธารณะหลายที่ และพื้นที่ส่วนตัวหนึ่งที่ สาธารณะแปลว่าทุกคนอ่านทุกอย่างข้างในได้ อย่าใส่รหัสผ่าน คีย์ API หรือรายชื่อลูกค้าลงในอิมเมจเด็ดขาด ต่อไปให้เปลี่ยนเลขเวอร์ชันทุกครั้งที่ push: 1.0 แล้ว 1.1 แล้ว 1.2 อย่าใช้ latest ตลอด เพราะจะไม่มีใครรู้ว่าข้างในคืออะไร

☸️ And what is Kubernetes?

Summary

Docker runs boxes on one computer. You watch them. Kubernetes runs boxes on many computers, and it watches them for you. You write a file that says what you want. Kubernetes makes the world match the file, all day and all night. It is powerful, but it is heavy. You do not need it for one small site.

摘要

Docker 在一台电脑上跑盒子,由你盯着。Kubernetes 在很多台电脑上跑盒子,并且替你盯着。你写一个文件说明你要什么,Kubernetes 就日夜不停地让现实符合这个文件。它很强大,但也很重。做一个小网站不需要它。

สรุป

Docker รันกล่องบนเครื่องเดียว โดยคุณเป็นคนเฝ้า Kubernetes รันกล่องบนหลายเครื่อง และเฝ้าให้คุณเอง คุณเขียนไฟล์บอกว่าต้องการอะไร แล้ว Kubernetes ทำให้โลกจริงตรงกับไฟล์นั้นทั้งวันทั้งคืน มันทรงพลังแต่ก็หนัก เว็บเล็ก ๆ เว็บเดียวไม่จำเป็นต้องใช้

People also write it K8s. There are eight letters between the K and the s, so they count them and write the number. You say it "kates". 人们也把它写成 K8s:K 和 s 中间有八个字母,就数出来写成数字。读作 “kates”。 คนยังเขียนย่อว่า K8s เพราะระหว่าง K กับ s มีตัวอักษรแปดตัว ก็เลยนับแล้วเขียนเป็นเลข อ่านว่า "เคทส์"

The five words

  • Cluster — all the computers, working as one. 集群 —— 所有电脑合起来当成一台用。 คลัสเตอร์ — คอมพิวเตอร์ทั้งหมดทำงานเหมือนเป็นเครื่องเดียว
  • Node — one computer inside the cluster. 节点 —— 集群里的一台电脑。 โหนด — คอมพิวเตอร์หนึ่งเครื่องในคลัสเตอร์
  • Pod — the smallest thing Kubernetes runs. Nearly always one container. Pod —— Kubernetes 运行的最小单位,几乎总是一个容器。 พ็อด — สิ่งที่เล็กที่สุดที่ Kubernetes รัน เกือบทุกครั้งคือคอนเทนเนอร์หนึ่งตัว
  • Deployment — your wish. "I want four pods of this image." Deployment —— 你的愿望:“这个镜像我要四个 pod。” ดีพลอยเมนต์ — ความต้องการของคุณ "ฉันต้องการพ็อดของอิมเมจนี้สี่ตัว"
  • Service — one steady address in front of all the pods. Service —— 所有 pod 前面那个不变的地址。 เซอร์วิส — ที่อยู่เดียวที่ไม่เปลี่ยน อยู่หน้าพ็อดทั้งหมด

What it does for you

  • It restarts dead boxes. A pod dies at 3 in the morning. A new one is running two seconds later. You are asleep. 它会重启死掉的盒子。凌晨三点有个 pod 死了,两秒后新的就在跑了。而你在睡觉。 มันรีสตาร์ทกล่องที่ตายให้ พ็อดตายตอนตีสาม อีกสองวินาทีตัวใหม่ก็ทำงานแล้ว ขณะที่คุณกำลังหลับ
  • It grows and shrinks. Many people at 8 pm? Ten pods. Nobody at 4 am? Two pods. 它会伸缩。晚上八点人多?十个 pod。凌晨四点没人?两个 pod。 มันขยายและหดได้ คนเยอะตอนสองทุ่ม? สิบพ็อด ไม่มีใครตอนตีสี่? สองพ็อด
  • It changes the version with no dark screen. It starts new pods, checks them, and only then stops the old ones. 换版本时不会黑屏。它先起新的 pod,检查好,然后才停掉旧的。 เปลี่ยนเวอร์ชันโดยจอไม่ดับ มันสร้างพ็อดใหม่ ตรวจสอบ แล้วค่อยหยุดตัวเก่า
  • It spreads the work. It puts pods on the computers that are not busy. 它会分摊工作。把 pod 放到不忙的机器上。 มันกระจายงาน เอาพ็อดไปวางบนเครื่องที่ยังไม่ยุ่ง

What it looks like

Same image you pushed. Two small files. Two commands. 还是你刚推送的那个镜像,两个小文件,两条命令。 อิมเมจตัวเดิมที่คุณเพิ่ง push ไฟล์เล็ก ๆ สองไฟล์ คำสั่งสองคำสั่ง

# deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: my-site spec: replicas: 4 selector: matchLabels: app: my-site template: metadata: labels: app: my-site spec: containers: - name: web image: yourname/my-site:1.0 ports: - containerPort: 80
kubectl apply -f deployment.yaml # tell it your wish kubectl get pods # see the four pods kubectl scale deployment my-site --replicas=8 kubectl delete pod my-site-abc12 # kill one, and watch it come back
Do you need it today? Probably not. One small site on one computer is a job for Docker. Kubernetes is for many services, on many computers, that must never stop. It brings a lot of new words and a lot of new files. Learn Docker first. Learn Kubernetes when a real problem asks for it. 今天你需要它吗?大概不需要。一台电脑上的一个小网站,Docker 就够了。 Kubernetes 是给很多台机器上很多个、绝不能停的服务用的。它带来一大堆新词和新文件。 先学 Docker,等真的遇到问题再学 Kubernetes。 วันนี้คุณจำเป็นต้องใช้ไหม? คงยัง เว็บเล็ก ๆ เว็บเดียวบนเครื่องเดียว เป็นงานของ Docker Kubernetes มีไว้สำหรับหลายบริการ บนหลายเครื่อง ที่ต้องไม่หยุดทำงานเลย มันมาพร้อมคำใหม่และไฟล์ใหม่เยอะมาก เรียน Docker ให้ได้ก่อน แล้วค่อยเรียน Kubernetes ตอนที่มีปัญหาจริงมาถาม
Want to try it for free? Docker Desktop has Kubernetes inside. Open SettingsKubernetes → tick Enable KubernetesApply. Wait some minutes. Then kubectl get nodes works on your own computer. 想免费试试?Docker Desktop 里就有 Kubernetes。打开 SettingsKubernetes → 勾选 Enable KubernetesApply,等几分钟, 然后在自己电脑上就能用 kubectl get nodes 了。 อยากลองฟรีไหม? Docker Desktop มี Kubernetes อยู่ข้างในแล้ว เปิด SettingsKubernetes → ติ๊ก Enable KubernetesApply รอสักครู่ จากนั้น kubectl get nodes จะใช้ได้บนเครื่องของคุณเอง

🚀 Where to go next

☸️ Kubernetes Lab — the next step. You made the box. Now let a machine run many copies of it, on many computers, and keep them alive while you sleep. Five machines, a free cluster on your own computer, and your image from section 6.
Kubernetes 实验室 —— 下一步。盒子你已经做好了, 现在让一台机器在很多电脑上跑很多份,并且在你睡觉时保持它们活着。 五台机器、自己电脑上的免费集群,还有第 6 节里你自己的镜像。

แล็บ Kubernetes — ขั้นต่อไป คุณสร้างกล่องแล้ว ทีนี้ให้เครื่องจักรรันมันหลายสำเนา บนหลายเครื่อง และดูแลให้มันไม่ตายตอนคุณหลับ เครื่องมือห้าตัว คลัสเตอร์ฟรีบนเครื่องของคุณเอง และอิมเมจของคุณจากหัวข้อที่ 6
Open ▸
📦 Write your own Dockerfile. Go slowly through every line: FROM, WORKDIR, COPY, RUN, CMD. One line at a time.
写你自己的 Dockerfile:一行一行慢慢过 FROM、WORKDIR、COPY、RUN、CMD。

เขียน Dockerfile ของคุณเอง ไล่ทีละบรรทัด FROM, WORKDIR, COPY, RUN, CMD
Open ▸
🤖 Run four services together on a Mac. A real AI agent in Docker, with voice in and voice out.
在 Mac 上同时跑四个服务:一个真实的 Docker AI 助手,能听也能说。

รันสี่บริการพร้อมกันบน Mac: เอเจนต์ AI จริงใน Docker ที่ฟังได้และพูดได้
Open ▸
🟨 Not sure about the React code? Learn the JavaScript words first: variable, function, event, array. Nine little machines.
对 React 代码没把握?先学 JavaScript 的词:变量、函数、事件、数组。九台小机器。

ยังไม่มั่นใจกับโค้ด React? เรียนคำศัพท์ JavaScript ก่อน: ตัวแปร ฟังก์ชัน อีเวนต์ อาร์เรย์ เครื่องมือเล็ก ๆ เก้าตัว
Open ▸

📌 Points to remember

  • An image is cold. A container is hot. docker run makes a hot one from a cold one. 镜像是冷的,容器是热的:docker run 用冷的做出热的。 อิมเมจคือกล่องเย็น คอนเทนเนอร์คือกล่องร้อน docker run ทำกล่องร้อนจากกล่องเย็น
  • Left is your computer, right is the box. -p 8080:80. 左边是你的电脑,右边是盒子里:-p 8080:80 ซ้ายคือเครื่องคุณ ขวาคือในกล่อง -p 8080:80
  • Slow lines at the top of the Dockerfile. Lines you change often go at the bottom. Dockerfile 里慢的行放上面,常改的行放下面。 บรรทัดที่ช้าไว้บนสุดของ Dockerfile บรรทัดที่แก้บ่อยไว้ล่างสุด
  • Two stages make a small image. Build with Node. Serve with nginx. 两个阶段做出小镜像:用 Node 构建,用 nginx 提供服务。 สองสเตจทำให้อิมเมจเล็ก สร้างด้วย Node เสิร์ฟด้วย nginx
  • One word turns private into public. servefunnel. Think before you type it. 一个词就从私有变公开:servefunnel。打之前先想一想。 คำเดียวเปลี่ยนจากส่วนตัวเป็นสาธารณะ servefunnel คิดก่อนพิมพ์
  • Never put a password inside an image. A public image is an open book. 绝不要把密码放进镜像:公开镜像就是一本摊开的书。 อย่าใส่รหัสผ่านไว้ในอิมเมจเด็ดขาด อิมเมจสาธารณะคือหนังสือที่เปิดอ่านได้
  • Kubernetes counts for you. You say the number. It keeps the number true. Kubernetes 替你数数:你说出数字,它让数字一直成立。 Kubernetes นับให้คุณ คุณบอกตัวเลข มันรักษาตัวเลขนั้นให้เป็นจริง

Thank you for learning with us today. Build a box, break it, and delete it. Nothing is lost. That is the best part. See you in the next lab. 感谢今天和我们一起学习。造一个盒子,弄坏它,再删掉它——什么都不会丢,这才是最棒的地方。下个实验室见。 ขอบคุณที่เรียนกับเราวันนี้ สร้างกล่อง ทำมันพัง แล้วลบทิ้ง ไม่มีอะไรหาย นั่นแหละคือส่วนที่ดีที่สุด แล้วเจอกันในแล็บหน้า