Docker เบื้องต้น
Tim Sangster
Software Engineer @ DataCamp
image hello-world จะพิมพ์ข้อความแล้วหยุดทำงาน
docker run hello-world
Hello from Docker!
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon created a new container from the hello-world image which runs the
executable that produces the output you are currently reading.
3. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
image ที่มี Python สามารถเริ่ม Python ได้ทันทีเมื่อสตาร์ท
docker run python3-sandbox
Python 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
...
....
>>> exit()
repl@host:/#
CMD <shell-command>
คำสั่ง CMD:
เริ่มต้นแอปพลิเคชันสำหรับรัน workflow หรือรับการเชื่อมต่อจากภายนอก
CMD python3 my_pipeline.py
CMD postgres
เริ่มต้นสคริปต์ที่ทำหน้าที่เปิดหลายแอปพลิเคชันพร้อมกัน
CMD start.sh
CMD python3 start_pipeline.py
$$
$$
image ที่มีความทั่วไปมากขึ้นต้องการ start command ที่ยืดหยุ่นกว่า
เริ่มต้น image
docker run <image>
เริ่มต้น image ด้วย start command กำหนดเอง
docker run <image> <shell-command>
เริ่มต้น image แบบ interactive ด้วย start command กำหนดเอง
docker run -it <image> <shell-command>
docker run -it ubuntu bash
| การใช้งาน | คำสั่งใน Dockerfile |
|---|---|
| เพิ่ม shell command ที่รันเมื่อสร้าง container จาก image | CMD <shell-command> |
| การใช้งาน | Shell Command |
|---|---|
| Override CMD ที่กำหนดใน image | docker run <image> <shell-command> |
| Override CMD ที่กำหนดใน image และรันแบบ interactive | docker run -it <image> <shell-command> |
Docker เบื้องต้น