---
# System prepended metadata

title: 02/27課程

---

# 02/27 容器化課程Podman compose (Java SpringBoot Restful API)
## podman run
### 前置
- [ ] [下載檔案](https://drive.google.com/drive/folders/1pV_uyvz36szjA7YWtW1WHPJHHJC277oe?usp=sharing)

- [ ] 解壓縮後請確認\springboot-restful-webservices\target\裡面沒有.jar檔或.jar.original檔，若有請刪除，否則podman build會失敗


- [ ] 包images(one stages)
`podman build -t springboot-restful-webservices-onestage -f ./Dockerfile.one`
- [ ] 包images(multi stages)**建議使用**
`podman build -t springboot-restful-webservices-multistage -f ./Dockerfile`


- [ ] 建立容器網路
`podman network create springboot-mysql-net`


### 練習podman run
- [ ] 啟動DB容器
`podman run --name mysqldb_dev  --network springboot-mysql-net -e MYSQL_ROOT_PASSWORD=dev -e MYSQL_DATABASE=employeedb -d mariadb`
- [ ] 啟動AP容器
`podman run -e "SPRING_PROFILES_ACTIVE=run" --network springboot-mysql-net --name springboot-restful-webservices-multi-stage -p 8080:8080  springboot-restful-webservices-multistage`
- [ ] 停止容器
`podman stop mysqldb_dev`
`podman stop springboot-restful-webservices-multi-stage`
- [ ] 刪除容器
`podman rm mysqldb_dev`
`podman rm springboot-restful-webservices-multi-stage`

- [ ] http://localhost:8080/api/users
- [ ] `curl --header "Content-Type: application/json" --request POST --data '{"firstName": "0227a","lastName":"0227a","email": "0227a@gmail.com"}' http://localhost:8080/api/users`

## podman compose
### 練習compose og
- [ ] 啟動
`podman compose -f .\docker-compose-origin.yml up -d`
- [ ] 確認啟動正常
`podman ps`
- [ ] 停止並刪除容器
`podman compose -f .\docker-compose-origin.yml down`

### 練習compose環境變數 
- [ ] 啟動
`podman compose -f .\docker-compose-env.yml --env-file=.env_env  up -d`
- [ ] 停止並刪除容器
`podman compose -f .\docker-compose-env.yml  down`

### 練習compose volumne
- [ ] 啟動
`podman compose -f .\docker-compose-volume.yml --env-file=.env_vol up -d`
- [ ] 停止並刪除容器
`podman compose -f .\docker-compose-volume.yml down `

## podman compose (PostgreSQL)
### 練習
- [ ] 啟動
`podman compose -f .\docker-compose-postgresql.yml --env-file=.env_postgres up -d`
- [ ] 停止並刪除容器
`podman compose -f .\docker-compose-postgresql.yml down`
- [ ] 確認PostgreSQL DB是否有存入值
`podman exec -it postgres psql -U postgres`
- [ ] PostgreSQL指令
```
\list (=show database)
\c employeedb (=use database)
\dt列出table
select * from users;
```



## 其他指令補充
docker-compose.yml 是 podman-compose 執行時預設會讀取的檔案
`podman compose up –d`
開始並建立資源
`podman compose down`
停止並移除資源
`podman compose rm`
刪除「已停止」的Container
`podman compose ps`
查看 Containers 的狀態
`podman compose start/stop/restart`
啟動/暫停/重啟動


## 補充
https://www.instagram.com/p/CzvyzYtNboo/?igsh=MzRlODBiNWFlZA==
