Mathurada Ekkapat
2 min readJun 6, 2018

ครั้งแรกกับการใช้ ์Nginx Web Server บน Docker

  1. ทำงานที่ 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

ถ้ามี Code HTML ยาวๆขึ้นมา หมายความว่า Web Server ทำงานได้

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

หลังสั่ง Command เพื่อ Mapping Port Docker จะทำการงานบางอย่าง

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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response