我的 NAS 上掛載多個 Docker 容器大部分容器都是使用 Python 撰寫的 API 服務下面就來介紹…
step 1
產出requirements.txt
如果要產出當前環境下所有依賴
pip freeze > requirements.txt如果只是要產出專案使用到的依賴,可以使用 pipreqs 套件
# 安裝套件
pip install pipreqs
# 產出requirements.txt
pipreqs .step 2
產出 Dockerfile
# image
FROM python:3.8.9
# 設定工作目錄
WORKDIR /api
# 複製套件檔
COPY . /api
# 安裝套件
RUN pip install --no-cache-dir --upgrade -r /api/requirements.txt
# 宣告使用的port
EXPOSE 8011
# 定義容器啟動命令
CMD ["python", "app/main.py"]step 3
在 NAS 的 Docker 資料夾下新增此次專案要使用的資料夾

step 4
將專案複製過去,app內就是專案原始碼

step 5
建立 image 檔
SSH 進 NAS並切換到專案目錄,執行下面指令
sudo docker build -t imgName .
step 6
部署 Container
登入NAS,進入 Docker 套件,切換到印象檔,確認剛才 build 出來的 image 已經出現

執行部署,記得要掛資料夾,將剛剛建立的專案路徑指定到容器內的/api路徑

一直下一步,完成後 container 會自動啟動,就可以測試服務是否已啟動了
Roulette odds never lie, and neither does a good AI tool. Platforms like AI powered help cut through the noise with smart, curated solutions that save time and boost efficiency.
Roulette odds never lie, and neither does a good AI tool. Platforms like AI powered help cut through the noise with smart, curated solutions that save time and boost efficiency.
Roulette odds never lie, and neither does a good AI tool. Platforms like AI powered help cut through the noise with smart, curated solutions that save time and boost efficiency.
Honestly, slotspalace10 has some pretty sweet slots. I’ve had some decent luck there, and the site itself is smooth as butter. Worth a spin if you’re looking for something new. slotspalace10