<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thiwthat Mongphut on Medium]]></title>
        <description><![CDATA[Stories by Thiwthat Mongphut on Medium]]></description>
        <link>https://medium.com/@thiwthat.mp?source=rss-e9f1e703c708------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*ZtcQ50Xk1b8YuMSy1W6Svg.jpeg</url>
            <title>Stories by Thiwthat Mongphut on Medium</title>
            <link>https://medium.com/@thiwthat.mp?source=rss-e9f1e703c708------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 15:03:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thiwthat.mp/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Docker คืออะไร การติดตั้ง วิธีใช้งานเบื้องต้น]]></title>
            <link>https://medium.com/cscmu-undergrad-seminar/docker-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99-c92d27633f7d?source=rss-e9f1e703c708------2</link>
            <guid isPermaLink="false">https://medium.com/p/c92d27633f7d</guid>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Thiwthat Mongphut]]></dc:creator>
            <pubDate>Fri, 10 Apr 2020 11:22:25 GMT</pubDate>
            <atom:updated>2020-04-10T11:22:25.134Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*glD7bNJG3SlO0_xNmSGPcQ.png" /></figure><p>ในบางครั้งการจะพัฒนาโปรเจคร่วมกันหลายคนมักจะเกิดปัญหาเครื่องเรารันได้ปกติ แต่พอไปรันเครื่องคนอื่นทำไมมันเกิดปัญหา หรือต้องเสียเวลาติดตั้งเยอะแยะเวลาจะใช้งานบนเครื่องอื่น วันนี้เราก็เลยจะมาทำความรู้จักกับ Docker สอนการติดตั้ง รวมถึงวิธีใช้งานเบื้องต้น</p><h4><strong>Docker คืออะไร</strong></h4><ul><li>Docker เป็น engine ที่ทำการจำลองสภาพแวดล้อมการทำงานของเครื่อง คล้ายกับ Virtual Machine เช่น VMWare, VirtualBox แต่เบากว่าเร็วกว่า ประหยัดทรัพยากรกว่า</li></ul><h4>การติดตั้ง</h4><ul><li>Docker Desktop สามารถใช้ได้ทั้งบน <a href="https://docs.docker.com/engine/installation/">Linux</a>, <a href="https://hub.docker.com/editions/community/docker-ce-desktop-mac">Mac</a> (OS X 10.11 or newer macOS) และ <a href="https://hub.docker.com/editions/community/docker-ce-desktop-windows">Windows</a>* (Windows 10 Pro 64bit ขึ้นไป) สำหรับ Mac และ Windows รุ่นต่ำกว่านั้นต้องทำการติดตั้ง <a href="https://docs.docker.com/toolbox/overview/">Docker Toolbox</a></li><li>สำหรับ Windows 10 Home Insider Preview build 19040 ขึ้นไปสามารถใช้เป็น Docker Desktop Edge 2.2.2.0 ซึ่งใช้ WSL 2 แทน Hyper-V</li><li>การใช้งาน Docker จะทำสั่ง command line เมื่อติดตั้งแล้วสามารถตรวจสอบการติดตั้งผ่าน terminal หรือ cmd ด้วยคำสั่งdocker -version หรือ docker -v</li></ul><h4>ทำความเข้าใจการใช้เบื้องต้น</h4><p>การจะใช้งาน Docker จะต้องมีการเขียน Dockerfile ซึ่งจะเป็นตัวกำหนดหน้าตาของ Docker Image และ Container ลำดับของการ build จะเป็นดังนี้คือ</p><blockquote>[Dockerfile] → build → [Docker Image] → run → [Container]</blockquote><p><strong>Docker Image</strong></p><ul><li>เสมือนแบบแปลนเพื่อจะสร้างเป็น container เหมือนเราสร้าง class</li><li>เกิดจากการ build Docker file</li><li>สามารถนำ image นี้ไปบันทึกไว้บน registry เพื่อให้ผู้อื่นนำไปใช้ได้</li></ul><p><strong>Container</strong></p><ul><li>เสมือนนำแปลนที่มีมาสร้างเป็น application จริง ตามสภาพแวดล้อมที่กำหนด</li><li>ถูกสร้างจาก Docker image</li></ul><p><strong>Parent Image</strong></p><ul><li>Image อื่นที่ Image เราอ้างอิงไปใช้งาน</li></ul><p><strong>Base Image</strong></p><ul><li>Image ที่ไม่มีการอ้างอิงถึง Image อื่น หรืออย่างน้อยอ้างอิงถึง Scratch Image ซึ่งเป็นตัวรากฐานสุดของแทบจะทุก Image (ข้างในเป็น linux)</li></ul><h4>เริ่มต้นใช้งานเบื้องต้นจากการสร้าง Container</h4><ol><li><strong>สร้าง NestJS Server</strong></li></ol><p>ในที่นี้เราอยากรันโปรเจค NestJS บน Docker เริ่มแรกเราก็ทำการสร้างโปรเจคมาสักอันนึงพร้อมรันทดสอบว่าปกติดีไหม</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sHxU1pC5Clc-NtRLrwLFgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b1-Rowr9wsHgk-WKfQsJow.png" /></figure><p><strong>2. สร้าง Dockerfile ภายในโปรเจคของเรา</strong></p><p>อาจสร้างผ่าน terminal หรือคลิกขวา New File บน Visual Studio Code ก็ได้ โดยทำการสร้างไฟล์ชื่อ Dockerfile ไม่ต้องใส่นามสกุลไฟล์ ทีนี้เราก็จะได้ Dockerfile มาแล้ว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*mRGv2dvrJdt0hZIBvHq88w.png" /></figure><p><strong>3. เขียน Dockerfile</strong></p><p>เราสามารถเขียน Dockerfile เพื่อตั้งค่าสภาพแวดล้อมทุกอย่างจากพื้นฐานเลยได้ แต่มีวิธีที่ง่ายกว่านั้นคือใช้ Image ที่มีอยู่แล้วซึ่งเราสามารถดึงมาใช้ได้ เช่น จาก <a href="https://hub.docker.com/">Docker Hub</a> ซึ่งมี Official Images ที่เชื่อถือได้ ทำให้เราประหยัดเวลาและไม่ต้องคอยอัพเดทสิ่งต่าง ๆ เอง</p><p>แต่ในที่นี้เราต้องการ Image ที่มี Linux Ubuntu alpine และ Node 10.0.0 ซึ่งมีอยู่แล้วบน Docker Hub เราจึงจะนำมาเป็น Parent Image เพื่อง่ายต่อการทำ</p><pre><strong>FROM</strong> node:10.0.0-alpine</pre><pre><strong>WORKDIR</strong> /usr/src/app</pre><pre><strong>COPY</strong> package*.json ./</pre><pre><strong>RUN</strong> npm install</pre><pre><strong>COPY</strong> . .</pre><pre><strong>EXPOSE</strong> 3000</pre><pre><strong>CMD</strong> [ &quot;npm&quot;, &quot;run&quot;, &quot;start&quot; ]</pre><p>อธิบายโค้ดข้างบน</p><ul><li><strong>FROM : </strong>อ้างอิงถึง parent image ที่เราต้องการใช้ ในที่นี้คือ node เวอร์ชัน 10.0.0-alpine</li><li><strong>WORKDIR </strong>: กำหนด working directory ภายใน Image</li><li><strong>COPY : </strong>copy ไฟล์ package*.json จาก directory ปัจจุบัน(ในที่นี้คือ package-lock.json และ package.json) ไปยัง working directory</li><li><strong>RUN </strong>: สั่งให้ทำการรัน npm install อยู่ในขั้นตอนการ build image</li><li><strong>EXPOSE : </strong>กำหนด port ของ container ซึ่งภายนอกจะติดต่อผ่าน port นี้</li><li><strong>CMD : </strong>คำสั่งเริ่มต้นเมื่อทำการเริ่ม container สามารถมีได้เพียงคำสั่งเดียวต่อหนึ่ง Dockerfile ในที่นี้ให้ทำการรัน npm run start เพื่อเริ่มทำงาน node</li></ul><p><strong>4. Build Docker Image</strong></p><p>เมื่อทำการเขียน Dockerfile เสร็จแล้วก็จะเป็นขั้นตอนการ build Docker image หากยังไม่ได้ทำการเปิด Docker Desktop ก็ทำการเปิดเหมือนเข้าโปรแกรมปกติก่อน จากนั้นใช้คำสั่งเพื่อทำการ build image</p><pre>docker build -t demo .</pre><p>สามารถใส่ tag เป็นเลขเวอร์ชันเพื่อง่ายต่อการจำได้</p><pre>docker build -t demo:1 .</pre><ul><li>-<strong>t </strong>demo:1<strong> </strong>คือ ทำการตั้งชื่อ image ว่า demo และให้เป็นเวอร์ชัน 1</li><li><strong>.</strong> คือ จะทำการหา Dockerfile ที่ current directory</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*-J-dWxAxEX8DhFiQqz8dZQ.png" /></figure><p>จะทำการ build ทีละ step ตามคำสั่งที่เราเขียนบน Dockerfile หากมีการอ้างอิงถึง image อื่นแล้วเราไม่เคย pull มาไว้บนเครื่องก็จะทำการดึงมาให้เองอัตโนมัติ</p><p>เมื่อทำการ build เสร็จแล้วสามารถใช้คำสั่งเพื่อเรียกดู image ที่มีอยู่ในเครื่องได้ดังนี้</p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*t2pcAJWCF8NX3rYNreJkTg.png" /></figure><p><strong>5. รัน Docker Container</strong></p><p>ทำการรัน container จาก image ที่เราสร้างโดยใช้คำสั่ง</p><pre>docker run --name demo-ctn -p 4000:3000 -d demo</pre><ul><li><strong>— name </strong>demo-ctn<strong> : </strong>ตั้งชื่อให้กับ container ในที่นี้ชื่อว่า demo-ctn โดยชื่อนี้สามารถใช้ในคำสั่ง start stop หรือ rm ที่ใช้สั่งการ container ได้เช่นกัน</li><li><strong>-p </strong>4000:3000 : เป็นการ map port ระหว่างเครื่องและ container ในที่นี้เราให้ภายนอกติดต่อ container ที่ port 3000 และเราจะใช้บนเครื่องที่ port 4000 เวลากำหนดก็จะเป็น 4000:3000</li><li><strong>-d : </strong>เป็นการสั่งให้ container รันแบบ background</li><li>demo : ชื่อ image ที่เราต้องการนำมาสร้างเป็น container</li></ul><p>สามารถเช็คว่ามี container อะไรอยู่บนเครื่องเราบ้างโดยใช้คำสั่ง</p><pre>docker ps -a</pre><ul><li><strong>-a : </strong>แสดง container ทั้งหมดไม่ว่าจะอยู๋ในสถานะใด</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pV4YM03NZbc-jIrTWpOROg.png" /></figure><p>ลองเข้า <a href="http://localhost:4000/">localhost:4000</a> เพื่อดูว่าปกติไหม เพียงเท่านี้ก็เป็นอันเสร็จสิ้นแล้ว :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*lu15csUVjKCyAmbrNZFWaQ.png" /></figure><h4>References</h4><ul><li><a href="https://medium.com/@noomerzx/%E0%B8%84%E0%B8%B9%E0%B9%88%E0%B8%A1%E0%B8%B7%E0%B8%AD-Docker-%E0%B8%89%E0%B8%9A%E0%B8%B1%E0%B8%9A%E0%B8%9C%E0%B8%B9%E0%B9%89%E0%B9%80%E0%B8%A3%E0%B8%B4%E0%B9%88%E0%B8%A1%E0%B8%95%E0%B9%89%E0%B8%99-c1b9dc3b3645">https://medium.com/@noomerzx/คู่มือ-docker-ฉบับผู้เริ่มต้น-c1b9dc3b3645</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c92d27633f7d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cscmu-undergrad-seminar/docker-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87-%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99-c92d27633f7d">Docker คืออะไร การติดตั้ง วิธีใช้งานเบื้องต้น</a> was originally published in <a href="https://medium.com/cscmu-undergrad-seminar">CSCMU Undergrad Seminar</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>