# Docker OS Part 2

<figure><img src="https://miro.medium.com/max/1400/1*vQK4s0lOiK1ZkcXxFNIMDQ.png" alt=""><figcaption><p>คู่มือ Docker ฉบับผู้เริ่มต้น. มักจะเป็นเรื่องยากในการที่เราต้องการจะพั… | by noomerZx | Medium</p></figcaption></figure>

## Tools

<table><thead><tr><th width="361.3333333333333">Figure</th><th>Name</th><th>Amount</th></tr></thead><tbody><tr><td><h3>Hardware </h3></td><td><br></td><td><br></td></tr><tr><td><p><img src="https://media-cdn.bnn.in.th/91940/Microsoft-Tablet-Surface-Laptop-Go-i5-8-256-GB-THJ-00022-1-square_medium.jpg" alt="" data-size="original"></p><p><br></p></td><td>Laptop</td><td>1</td></tr><tr><td><h3>Software </h3></td><td><br></td><td><br></td></tr><tr><td><img src="https://miro.medium.com/max/1400/1*vQK4s0lOiK1ZkcXxFNIMDQ.png" alt=""><br></td><td>Docker </td><td>-</td></tr></tbody></table>

## Introduction

### Install environment&#x20;

ติดตั้ง environment แล้วมาฟังเนื้อหากันก่อน

1. ทำการติดตั้งตัวจัดการ internet

```
$ sudo apt-get install net-tools
```

2\. ทำการติดตั้ง docker image mysql และ word press

<pre><code><strong>$ docker pull mysql:5.7
</strong>$ docker pull wordpress
</code></pre>

### Docker Compose คืออะไร

&#x20;     Docker compose นั้นว่าง่ายๆ จะคล้ายๆกับ script คำสั่ง ที่เอาไว้สร้าง container หลายๆอันขึ้นมาพร้อมกัน โดยใช้คำสั่งเดียว ซึ่งปกติเราเวลาจะสร้างเจ้า container จะสร้างจาก image ตัวอย่างเช่น ถ้าจะทดสอบ wordpress เราจะต้องสร้างเจ้า container mysql , container httpd หรือ container nginx หรือ อาจมากกว่านั้นในกรณีที่เป็นโปรเจคอื่นที่ใช้ technology/service เยอะๆ และมันเชื่อมต่อกัน\
&#x20;     ปัญหาคือเราก็ต้องมาสร้าง container ทีละอัน และทำการ config ทีละอัน อีกที ซึ่งมันจะเสียเวลาอย่างมากเพราะ        ปัญหาที่กล่าวมาข้างต้นเลยเกิด docker compose ขึ้นมา คือเราสามารถกำหนดไว้ในไฟล์ docker-compose.yml เลย ว่าใช้ services อะไรบ้าง ตั้งค่าไรบ้าง จากนั้นก็ใช้คำสั่ง run command เจ้า docker-compose โดยใช้คำสั่ง docker-compose up -d แค่บรรทัดเดียว มันก็จะทำการสร้าง container ทุกๆอันให้เราอัตโนมัติ ตามค่า config ที่เราตั้งไว้\
&#x20;     ในการใช้งาน docker บางครั้งเราต้องใช้การติดต่อสื่อสารระหว่าง container เพื่อทำการรับส่งข้อมูลในการทำงาน ซึ่งเมื่อเป็นระบบที่ใช้งานจริง จะมี container หลายตัวมาประกอบกันเช่น container จัดการ database, จัดการหน้าเว็บ, จัดการการรับข้อมูลผ่าน sensor ขึ้นไปบนเว็บเป็นต้น เมื่อทำงานพร้อมกันทำให้ต้องคอยควบคุม container หลายตัวพร้อมกันและการทำ [docker link](https://docs.docker.com/network/links/) และ [docker volume](https://docs.docker.com/storage/volumes/) จะยุ่งยากในการกำหนดค่าในการทำงาน\
&#x20;     Docker compose จึงเป็นตัวช่วยในการจัดการงานที่ซับซ้อนให้ง่ายขึ้นโดยการจัดการ container หลายตัวพร้อมกันให้สามารถทำงานร่วมกันได้โดยที่ไม่ต้อง link ให้ยุ่งยาก ซึ่งมักจะทำเป็นตัวจัดการ service ที่จะใช้งานประกอบกัน

<figure><img src="https://paper-attachments.dropbox.com/s_C113432522B99E8D1784E93A637A5C8EEA0BBA87ECE8D4B97D908798038CE56B_1662442387952_image.png" alt=""><figcaption></figcaption></figure>

### Remote container

VScode remote container เป็นส่วนเสริมที่ให้คุณสามารถออกแบบ Docker container ได้อย่างอิสระ โดยที่จะทำการเชื่อมโฟลเดอร์ที่เราทำงานเข้ากับตัว container อัตโนมัติ โดยสามารถตั้งค่าผ่าน [devcontainer.json](https://code.visualstudio.com/docs/remote/containers#_create-a-devcontainerjson-file) ซึ่งจะเป็นไฟล์ที่คอยกำหนดขั้นตอนการทำงานของตัว docker ทั้งก่อนและหลังการ build โดยภายในจะติดตั้ง libraries, package หรือ runtime เพื่อที่จะพัฒนาหรือออกแบบระบบ

<figure><img src="https://code.visualstudio.com/assets/docs/remote/containers/architecture-containers.png" alt=""><figcaption><p>Container Architecture</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/general/docker-os/docker-os-part-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
