เริ่มจากสร้างไฟล์ docker-compose.yml
version: '2.0'
services:
web:
image: nginx:1.13.0-alpine
container_name: wrk-nginx
restart: always
ports:
- "9001:80"
volumes:
- ./html/:/usr/share/nginx/html
![](https://thana.in.th/wp-content/uploads/2020/05/Screen-Shot-2563-05-06-at-17.55.13.png)
image: nginx:1.13.0-alpine
เลือก image nginx:1.13.0-alpine ซึ่งเป็นตัว image ที่ใช้ Alpine Linux project (โครงการของ Alpine Linux นี้ก็ถูกพัฒนาขึ้นมาเพื่อตอบโจทย์การใช้ Container ให้มีขนาดไม่เกิน 8MB และใช้พื้นที่รวมไม่เกิน 130 MB รวมถึงยังถูกออกแบบมาให้มีความปลอดภัยสูง)
container_name: wrk-nginx
ตั้งชื่อ Container
restart: always
restart เมื่อ Container ถูกปิด
ports:
- "9001:80"
Map port 9001 จาก container ไป 80 ของ nginx image
volumes:
- ./html/:/usr/share/nginx/html
Map Volumn directory html ไป /usr/share/nginx/html ของ nginx image
create directory ‘html’ และ create file index.html เพื่อทดสอบ
<html>
<h1>Hello Wrk-Nginx</h1>
</html>
![](https://thana.in.th/wp-content/uploads/2020/05/Screen-Shot-2563-05-06-at-18.11.39.png)
เสร็จแล้วรัน command
docker-compose up -d
![](https://thana.in.th/wp-content/uploads/2020/05/Screen-Shot-2563-05-06-at-17.50.38.png)
ตรวจสอบได้ container จาก command
docker ps -a
![](https://thana.in.th/wp-content/uploads/2020/05/Screen-Shot-2563-05-06-at-17.51.53-1024x48.png)
เปิด browser ทดสอบ 127.0.0.1:9001
![](https://thana.in.th/wp-content/uploads/2020/05/Screen-Shot-2563-05-06-at-18.14.08-1024x655.png)
(Visited 5,288 times, 1 visits today)