ครั้งแรกกับการใช้ ์Nginx Web Server บน Docker
- ทำงานที่ Host (Window OS)
// Check Docker
> docker -v
// Download image
> docker pull centos
> docker images
2. ทำงานที่ Container (CentOS)
// Open Image
> docker run -it centos
> yum update
ปล. -it = Interactive and Terminal Mode
// Install Nginx Web Server
> yum install epel-release // Step 1. Add Repository
> yum install nginx // Step 2. Install Nginx
// Start nginx
> nginx
3. ดูว่า Web Server ทำงานอยู่
//Open Container
> docker exec -it <container_name> <command_path>
- exec = execute command = run
- <container_name>ได้มาจากการที่ docker เป็นคน Generate เมื่อเราไม่ได้ทำการกำหนดค่า
- <command_path> ใช้ /bin/bash เป็น default path
// Test Web Server
> curl localhost

4. ออกจาก Container
// Kill process in container
> exit
5. สร้างและบันทึก Image (Build Images)
> docker ps -a // view process container
> docker commit <Container_id > <new_images>
- <Container_id> = สามารถระบุ Container_id 3 digit หน้าได้ เช่น afe
- <new_images> = ตั้งชื่อ images ชื่อ centos-nginx

> docker images // view new image

6. วิธีการ Expose Port จากใน Container ออกมาข้างนอก
สามารถ Mapping Port ให้สมารถมองเห็น Nginx Web Sever ใน เครื่อง Host ( Window OS)
> docker run -it -p <port_host>:<port_server> nginx

หลังจากนั้นจะลองเข้า localhost:80 เพื่อดูว่าเรา Host สามารถที่จะมองเห็น Web Server บน Docker ไหม
