> For the complete documentation index, see [llms.txt](https://docs.aic-eec.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aic-eec.com/general/docker-os/docker-os-part-2/part-1-docker-communication.md).

# Part 1 : Docker communication

การติดต่อ

## Part 1-1 : Setup Container

1. สร้างไดเรคทอรี่เก็บฐานข้อมูลลงบนเครื่องคอมพิวเตอร์

```bash
$ mkdir -p Docker_OS_part2/database_<STUDENT_ID>
```

2\. ทำการรัน mysql โดยมีการเก็บฐานข้อมูลบนเครื่อง&#x20;

```bash
$ docker run --name <name_database_container> -v Docker_OS_part2/database_<STUDENT_ID>:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=<Your password> -d mysql:5.7
```

`3.` ตรวจสอบการทำงานของ docker&#x20;

```bash
$ docker ps
```

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

4\.  ทำการเข้าไปในคอนเทนเนอร์ mysql ด้วยคำสั่ง exec

```bash
$ docker exec -it <name_database_container> mysql -u root -p
```

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

5\.  ทำการสร้าง Database ด้วยคำสั่ง&#x20;

```sql
mysql> create database wordpress;
```

`6.` ทำการตรวจสอบ wordpress database เมื่อตรวจสอบแล้วจึงทำการออกจาก database

```sql
mysql> show databases;
mysql> use wordpress;
mysql> show tables;
mysql> exit
```

7\. ทำการรัน wordpress  โดยทำการลิ้งกับฐานข้อมูล

```bash
$ docker run --name <name_dashboard_container> -p 8080:80 --link <name_container>:mysql -d wordpress  
```

8\. ตรวจสอบการทำงานของ word press และ mysql container

```bash
$ docker ps
```

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

ในหน้าต่าง Docker desktop ก็สามารถดูสภานะและทำการจัดการเจ้า container ได้เช่นกัน

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

9\. ทำการสร้าง docker network เพื่อเป็นตัวกลางในการติดต่อระหว่าง container&#x20;

```bash
$ docker network create --attachable <name of your network>
```

10\. ทำการเชื่อมต่อ network  ของ container เพื่อต่อกับ database และหน้าเว็บ

```bash
$ docker network connect <name of your network> <name_database_container>
$ docker network connect <name of your network> <name_dashboard_container>
```

{% hint style="info" %}
Tips : ทำการตรวจสอบ ip ของ container ด้วยคำสั่ง inspect

`$ docker inspect test_wordpress | grep IP`
{% endhint %}

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

### Part 1-2 : Test docker container communication

1. เปิดเว็บบราวเซอร์บนเครื่องแล้วเข้าไปที่ "localhost:8080" จะขึ้นหน้าต่างตัวอย่างการใช้งาน word press

<div align="left"><figure><img src="https://paper-attachments.dropbox.com/s_C113432522B99E8D1784E93A637A5C8EEA0BBA87ECE8D4B97D908798038CE56B_1662449803340_image.png" alt=""><figcaption></figcaption></figure> <figure><img src="https://www.dropbox.com/paper/ep/redirect/image?url=https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_C113432522B99E8D1784E93A637A5C8EEA0BBA87ECE8D4B97D908798038CE56B_1662449858883_image.png&#x26;hmac=CiXnMXwnEDi%2BK1tQP5VNCOtr4yQDWaeTCIqASGu%2Fz6w%3D" alt=""><figcaption></figcaption></figure></div>

2\. ใส่รายละเอียดของดาต้าเบสของเราลงในช่อง

> Username : root
>
> Password : Password ที่ตั้งตอนรัน docker&#x20;

<div><figure><img src="https://paper-attachments.dropbox.com/s_C113432522B99E8D1784E93A637A5C8EEA0BBA87ECE8D4B97D908798038CE56B_1662450141079_image.png" alt=""><figcaption></figcaption></figure> <figure><img src="https://www.dropbox.com/paper/ep/redirect/image?url=https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_C113432522B99E8D1784E93A637A5C8EEA0BBA87ECE8D4B97D908798038CE56B_1662450309361_image.png&#x26;hmac=VAhYm6xYoS4MQrjGUZS37DJiir0YZWnPO7dFiu6QaNE%3D" alt=""><figcaption></figcaption></figure></div>

3\. กรอกข้อมูลหน้าเว็บของเรา&#x20;

<div><figure><img src="https://paper-attachments.dropbox.com/s_C113432522B99E8D1784E93A637A5C8EEA0BBA87ECE8D4B97D908798038CE56B_1662450444376_image.png" alt=""><figcaption></figcaption></figure> <figure><img src="https://www.dropbox.com/paper/ep/redirect/image?url=https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_C113432522B99E8D1784E93A637A5C8EEA0BBA87ECE8D4B97D908798038CE56B_1662365546433_image.png&#x26;hmac=0KEM61fmYWMJPhxkn69tcIRlD4dj5nw9E%2FoPbwesh9U%3D" alt=""><figcaption></figcaption></figure></div>

4\. ทำการ Login เข้าสู่ dash board

<div><figure><img src="https://paper-attachments.dropbox.com/s_C113432522B99E8D1784E93A637A5C8EEA0BBA87ECE8D4B97D908798038CE56B_1662450557702_image.png" alt=""><figcaption></figcaption></figure> <figure><img src="https://www.dropbox.com/paper/ep/redirect/image?url=https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_C113432522B99E8D1784E93A637A5C8EEA0BBA87ECE8D4B97D908798038CE56B_1662450573931_image.png&#x26;hmac=JdfBrqGTZtXFPm3mpZnitE%2B6oK2E3V1BCzjgvvsnJnU%3D" alt=""><figcaption></figcaption></figure></div>

5\. กลับไปตรวจสอบข้อมูลบน database ด้วยขั้นตอน part 1-1 : ข้อที่ 4-6 แล้วบันทึกผลอีกครั้ง


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
