|
1 | 1 | {:title "Today I Learned"
|
2 | 2 | :page-index 0}
|
3 | 3 |
|
| 4 | +## 2024-07-25 |
| 5 | + |
| 6 | +`docker ps` 和 `docker compose ps` 命令,有一个可以指定输出格式的参数 `--format`[^1],默认是 table。 |
| 7 | + |
| 8 | +可以指定按 json 格式输出,再结合 jq 进行格式化,比如: |
| 9 | + |
| 10 | +```bash |
| 11 | +docker compose ps --format json | \ |
| 12 | +jq '{Service: .Service, State: .State, Status: .Status}' |
| 13 | +``` |
| 14 | + |
| 15 | +```json |
| 16 | +{ |
| 17 | + "Service": "hive-metastore", |
| 18 | + "State": "running", |
| 19 | + "Status": "Up 55 minutes (healthy)" |
| 20 | +} |
| 21 | +{ |
| 22 | + "Service": "mc", |
| 23 | + "State": "running", |
| 24 | + "Status": "Up 55 minutes" |
| 25 | +} |
| 26 | +{ |
| 27 | + "Service": "metastore_db", |
| 28 | + "State": "running", |
| 29 | + "Status": "Up 55 minutes" |
| 30 | +} |
| 31 | +{ |
| 32 | + "Service": "minio", |
| 33 | + "State": "running", |
| 34 | + "Status": "Up 55 minutes" |
| 35 | +} |
| 36 | +{ |
| 37 | + "Service": "spark-hudi", |
| 38 | + "State": "running", |
| 39 | + "Status": "Up 54 minutes (healthy)" |
| 40 | +} |
| 41 | +{ |
| 42 | + "Service": "starrocks-fe", |
| 43 | + "State": "running", |
| 44 | + "Status": "Up 55 minutes (unhealthy)" |
| 45 | +} |
| 46 | +{ |
| 47 | + "Service": "starrocks-toolkit", |
| 48 | + "State": "running", |
| 49 | + "Status": "Up 53 minutes" |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +`--format` 参数默认的是 table,而 table 可以指定 TEMPLATE[^2],比如: |
| 54 | + |
| 55 | +```bash |
| 56 | +docker compose ps --format "table {{.Service}}\t{{.State}}\t{{.Status}}" |
| 57 | +``` |
| 58 | + |
| 59 | +``` |
| 60 | +SERVICE STATE STATUS |
| 61 | +hive-metastore running Up 42 minutes (healthy) |
| 62 | +mc running Up 42 minutes |
| 63 | +metastore_db running Up 42 minutes |
| 64 | +minio running Up 42 minutes |
| 65 | +spark-hudi running Up 42 minutes (healthy) |
| 66 | +starrocks-fe running Up 42 minutes (unhealthy) |
| 67 | +starrocks-toolkit running Up 41 minutes |
| 68 | +``` |
| 69 | + |
| 70 | + |
4 | 71 | ## 2023-08-10
|
5 | 72 |
|
6 | 73 | 可选链运算符 (?.) (Optional chaining) 允许读取位于连接对象链深处的属性的值,而不必明确验证链中的每个引用是否有效。在引用为空 (nullish) (null 或者 undefined) 的情况下不会引起错误,该表达式短路返回值是 undefined。
|
@@ -63,3 +130,7 @@ In Git, when you run a `git pull` command, it combines two actions: `git fetch`
|
63 | 130 | ## 2023-07-19
|
64 | 131 |
|
65 | 132 | JSONPath is a query language for JSON, similar to XPath for XML.
|
| 133 | +
|
| 134 | +
|
| 135 | +[^1]: [docker ps | Docker Docs](https://docs.docker.com/reference/cli/docker/container/ls/) |
| 136 | +[^2]: [Format command and log output | Docker Docs](https://docs.docker.com/config/formatting/) |
0 commit comments