Memo Dockerfile

Chutipon Pongpanit (Aof)
1 min readJan 8, 2019

--

Base Docker 17.05 and higher (remote build-context)
Instruction ของ Dockerfile ใช้ทำอะไรบ้าง ใช้อย่างไร

  • FROM
    Dockerfile มักจะเริ่มด้วยคำสั่งนี้ ใช้สร้าง image หรือใช้ build stage เพื่อพื้นที่อิสระของมัน ซึ่งมันทำงานบน image ทำให้ต้องโหลด image มาก่อนแล้วจะใช้งานต่อได้
  • WORKDIR
    ระบุ directory สำหรับทำงานคำสั่งด้านล่างต่อไป ถ้าหากยังไม่มีจะถูกสร้างขึ้น ตามคำแนะนำเราควร relative path เสมอ สามารถใช้ environment variables ได้ด้วยน้ะ example
    ENV DIRPATH /path
    WORKDIR $DIRPATH/$DIRNAME
    RUN pwd
  • ADD or COPY
    เนื่องจากทั้ง 2 คำสั่งมีการทำงานคล้ายกัน เลยขอรวบไว้เลย ส่วนตัวแล้วใช้ COPY แล้วดูเข้าใจง่ายกว่า ADD
    คำสั่ง COPY ใช้ copy local file ไปไว้ใน container
  • RUN
    ใช้ execute คำสั่งต่างๆ ซึ่ง on top บน image ในการใช้คำสั่งตัวนี้เราจำเป็นต้องรู้จักรูปแบบของมัน ซึ่งมี 2 แบบ
    (1) shell form — RUN <command>
    (2) exec form—RUN ["executable", "param1", "param2"]
  • EXPOSE
    เพื่อระบุเลข ports ให้กับ container
  • ENV
    สร้าง environment variables ด้วยการใช้ ENV will persist when a container
  • CMD
    เป็นคำสั่งใช้งาน software บน image
    (1) exec form — CMD ["executable","param1","param2"] (exec form, this is the preferred form)
    (2) ENTRYPOINT — CMD ["param1","param2"]
    (3) shell form — CMD command param1 param2

--

--

Chutipon Pongpanit (Aof)
Chutipon Pongpanit (Aof)

Written by Chutipon Pongpanit (Aof)

Aoftionstyle idea here #idea is anything happen faster speed of light then captured in the chest. no ✔ no ✘ just Casually open chest beacause world need you

No responses yet