回到軟體工程分享頁面
此網站目的是希望透過大家在這邊可以找到需要的資料及工具,也歡迎大家一同加入共同筆記團隊,一同分享各式各項的資訊或工具,立刻申請加入HackMD團隊吧!!! 
另外也建立Discord群組
,歡迎大家加入
Podman
https://podman.io
Apache License 2.0
Podman on Windows
Install with executable file
Document: https://github.com/containers/podman/blob/main/docs/tutorials/podman-for-windows.md
Install with Chocolatey
透過Chocolatey套件管理進行安裝,開啟Administrator權限的PowerShell,執行以下指令
Initial VM(Podman Machine)
Podman安裝完成後開啟PowerShell,直接在預設路徑(C:\Users\User)
執行以下指令,進行Podman Machine的初始化
Starting Machine
完成初始化後,執行以下指令啟動Podman Machine
Podman on MacOS
Install
Start Podman VM
Stop Podman VM
Uninstall
First Podman Command
接下來可以進行一個簡單的測試,執行以下指令
透過這個範例會運行一個基於UBI8 Micro Image的容器,並執行 date 命令,得到終端機回覆容器內的時間
Command
Stopping Container
Stopping Pod
Stopping Machine
Removing Container
Removing Pod
Removing Machine
Display container configuration
Others
查詢所有Podman提供可用的指令
查詢所有指令可用的參數
Trouble Shooting
Trouble Shooting with Podman
Download Nginx Image
在啟動Nginx之前,需要先將Nginx的映象檔下載到VM主機中,可以先執行以下指令
找到相關的映象檔,接著可以再執行指令下載映像檔
Starting Nginx
啟動方式有兩種,分別如下
- 直接啟動Container
- 先建立Pod,再啟動Container到Pod內
Creating Pod
執行以下指令建立一個Pod
- 參數說明
- --name nginxapp:設定Pod的名稱為"nginxapp"
- -p 8080:80:設定端口轉發,將主機的8080端口映射到Pod內的80端口,這樣可以通過主機的8080端口訪問Pod內的應用
完成後可以執行以下指令,查詢剛建立名稱為nginxapp的Pod
Creating Container
若是直接啟動Container的話,請跳至直接建立並啟動Container章節;若是已有執行Creating Pod,則接下來要在nginxapp這個Pod中建立並啟動新的Container,請跳至已建立Pod後,啟動Container章節
直接建立並啟動Container
執行以下指令
- 參數說明
- --name:設定Container的名稱為"nginx-server"
- -d:以分離模式運行容器,即容器在後台運行。
- nginx:latest:指定要運行的容器映像,這裡使用的是nginx映像的最新版本
已建立Pod後,啟動Container
執行以下指令
- 參數說明
- --pod:將Container加到指定的Pod之中
- --name:設定Container的名稱為"nginx-server"
- -d:以分離模式運行容器,即容器在後台運行。
- nginx:latest:指定要運行的容器映像,這裡使用的是nginx映像的最新版本
Check instance if its running
成功啟動Container後,執行以下指令,也可以直接開啟瀏覽器連上 http://localhost:8080 ,將會顯示Nginx預設網頁
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Adding Custom HTML file to be uploaded to Nginx
想要把靜態網頁加入容器中,有兩種方法:
- 透過Podman手動複製檔案
- 設定volume掛載到Container
在此之前需要先確認兩點,分別為
- Nginx預設網頁路徑
透過指令進入Nginx容器,確認Nginx預設的網頁資料夾路徑在/usr/share/nginx/html
- 在Podman VM主機中靜態網頁的檔案路徑
PPodman VM(Podman Machine)在啟動時,會將硬碟掛載到根目錄底下的mnt之中,我們可以透過指令連進VM主機確認
透過Podman手動複製檔案
接下來我們就可以透過指令把檔案複製到Container之中
注意!目前仍在VM主機中
完成後再次開啟瀏覽器連上 http://localhost:8080/<檔案名稱>.html ,即可載入客製的靜態頁面
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
設定volume掛載到Container
範例以本機資料夾: D:\container\html掛載至Container內
由於Windows GitBash會轉換路徑,導致無法找到對應的檔案或資料夾,所以請使用PowerShell來執行
疑問
設定Port Forwarding低於1024,如主機Port 80映射至Container Port 80
若跳出上面的錯誤訊息,根據啟動VM時的系統訊息
This machine is currently configured in rootless mode. If your containers
require root permissions ****(e.g. ports < 1024), or if you run into compatibility
issues with non-podman clients, you can switch using the following command:
podman machine set –rootful
原因為使用port低於1024時,必須將權限設為root,否則在啟動Container時將會發生錯誤
執行以上指令後,請重新建立Pod及Container,即可用 http://localhost:80 連到網站