Part 2 : Basic Docker OS and Linux CLI

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

Part 2-1 : Pull & start the container

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

$ docker ps

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

$ docker pull centos

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

$ docker images

4. ทำการรัน container ด้วยคำสั่ง

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

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

$ docker ps

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

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

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

$ yum update

8. เนื่องจากไม่สามารถติดต่อผ่าน centos server ได้จึงต้องทำการชี้ที่อยู่ไป centos server ที่ออนไลน์


$ 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 แล้วลองใช้งาน

$ 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 ด้วยคำสั่ง

$ docker ps

Start docker container

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

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

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

$ tree /home

Save docker container

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

$ docker ps

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

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

Last updated

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University