> 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-1/part-2-basic-docker-os-and-linux-cli.md).

# Part 2 : Basic Docker OS and Linux CLI

ทำการศึกษาและใช้งาน Docker container

### Part 2-1 : Pull & start the container

1. ทำการตรวจสอบการทำงาน docker container ด้วยคำสั่ง docker ps&#x20;

```bash
$ docker ps
```

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

2\. ทำการทดสอบ pull image centos มาทดสอบ

```bash
$ docker pull centos
```

3\. ทำการตรวจสอบด้วยคำสั่ง docker images&#x20;

```
$ docker images
```

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

```
$ docker run -d -t --name <name of docker container> centos  
```

5\. ทำการตรวจสอบ container ด้วย docker ps อีกครั้ง&#x20;

```
$ docker ps
```

6\. เข้าไปใน container เพื่อใช้งาน CentosOS

```
$ docker exec -it <name of docker container> bash
```

7\. ทำการทดสอบการดึง package ดู

```
$ yum update
```

8\. เนื่องจากไม่สามารถติดต่อผ่าน [centos server](https://techglimpse.com/failed-metadata-repo-appstream-centos-8/) ได้จึงต้องทำการชี้ที่อยู่ไป centos server ที่ออนไลน์&#x20;

```bash

$ cd /etc/yum.repos.d/
$ sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
$ sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
```

9\. ทำการทดสอบ update อีกครั้ง

```
$ yum update -y
```

10\. ทำการติดตั้ง package tree แล้วลองใช้งาน&#x20;

```
$ yum install tree && tree
```

### Part 2-2 : Management container

**Stop docker container**

1. ออกจาก docker container แล้วพิมคำสั่งหยุดการทำงานของ CentosOS ด้วยคำสั่ง

```
$ exit$ docker stop <name of docker container>
```

2\. ตรวจสอบการทำงานของ docker ด้วยคำสั่ง&#x20;

```
$ docker ps
```

**Start docker container**&#x20;

1. ทำการ start แล้วเข้าไปยัง docker อีกครั้ง

```
$ docker start <name of docker container>
$ docker exec -it <name of docker container> bash
```

2\. ทดสอบคำสั่งที่เคยติดตั้งไปก่อนหน้า&#x20;

```
$ tree /home
```

**Save docker container**&#x20;

1. เปิด WSL Ubuntu version ที่พึ่งใช้งานไปมาอีกหน้าต่างหนึ่ง แล้วพิมคำสั่งตรวจสอบการทำงานของ docker container&#x20;

```
$ docker ps
```

`2.` ทำการบันทึกการเปลี่ยนแปลงด้วยคำสั่ง&#x20;

```
$ sudo docker commit -m "Install tree" <Container ID> <Image>
```
