Docker学习(05)——日志、元数据、进程的查看

1. 后台启动容器

docker run -d 镜像名

2. 查看日志

docker logs [参数选项]

参数说明:

--details        Show extra details provided to logs
  -f, --follow         Follow log output
      --since string   Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
  -n, --tail string    Number of lines to show from the end of the logs (default "all")
  -t, --timestamps     Show timestamps
      --until string   Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)

例如:

[root@192 ~]# docker run -d tomcat
b39af6be1dbed6773039b452de09768c80d4a990122e96bdfc2dbe195de6a2f9
[root@192 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND             CREATED         STATUS        PORTS      NAMES
b39af6be1dbe   tomcat    "catalina.sh run"   3 seconds ago   Up 1 second   8080/tcp   affectionate_jennings
[root@192 ~]# docker logs -f -t --tail 10 b39af6be1dbe
2021-09-25T10:58:39.694064292Z 25-Sep-2021 10:58:39.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
2021-09-25T10:58:39.699042606Z 25-Sep-2021 10:58:39.698 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].
2021-09-25T10:58:39.699145479Z 25-Sep-2021 10:58:39.699 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
2021-09-25T10:58:39.702645516Z 25-Sep-2021 10:58:39.702 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1k  25 Mar 2021]
2021-09-25T10:58:40.102701946Z 25-Sep-2021 10:58:40.102 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
2021-09-25T10:58:40.136319168Z 25-Sep-2021 10:58:40.136 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [704] milliseconds
2021-09-25T10:58:40.201997116Z 25-Sep-2021 10:58:40.201 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
2021-09-25T10:58:40.202194480Z 25-Sep-2021 10:58:40.202 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/10.0.11]
2021-09-25T10:58:40.214552513Z 25-Sep-2021 10:58:40.214 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
2021-09-25T10:58:40.227665014Z 25-Sep-2021 10:58:40.227 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [91] milliseconds

3. 查看容器中的进程信息

docker top 容器id

例如:

[root@192 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND             CREATED         STATUS         PORTS      NAMES
b39af6be1dbe   tomcat    "catalina.sh run"   5 minutes ago   Up 5 minutes   8080/tcp   affectionate_jennings
[root@192 ~]# docker top b39af6be1dbe
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                3050                3029                1                   18:58               ?                   00:00:06

4. 查看镜像元数据

docker inspect [参数选项]

参数说明:

-f, --format string   Format the output using the given Go template
-s, --size            Display total file sizes if the type is container
      --type string     Return JSON for specified type

例如:

[root@192 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND             CREATED         STATUS         PORTS      NAMES
b39af6be1dbe   tomcat    "catalina.sh run"   7 minutes ago   Up 7 minutes   8080/tcp   affectionate_jennings
[root@192 ~]# docker inspect b39af6be1dbe
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值