docker--程序自启动
能否在docker的ubuntu环境中创建service?
不能。
原因:
这个错误表明你的系统没有使用 systemd
作为初始化系统(init system)。Ubuntu 通常默认使用 systemd
,但某些特殊环境(如 Docker 容器、WSL 或某些嵌入式系统)没有使用 systemd
。
新容器构建程序自启动
Dockerfile构建自启动程序的镜像
链接
构建自启动容器
链接
旧容器构建程序自启动
docker中程序的日志查看
docker logs
作用:获取容器的日志。
docker logs --help
Usage: docker logs [OPTIONS] CONTAINERFetch the logs of a containerAliases:docker container logs, docker logsOptions:--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)
选项 | 作用 | 示例 |
---|---|---|
-f 或 --follow | 实时跟踪日志输出(类似 tail -f ) | docker logs -f my_container |
-t 或 --timestamps | 显示每条日志的时间戳 | docker logs -t my_container |
--tail N | 仅显示最后 N 行日志 | docker logs --tail 100 my_container |
--since TIME | 显示某个时间点之后的日志 | docker logs --since 2023-01-01T00:00:00Z my_container |
--until TIME | 显示某个时间点之前的日志 | docker logs --until 10m ago my_container |
案例
docker logs -ft auto_startup_test
# 查看最后 50 行
docker logs --tail 50 auto_startup_test# 查看最近 2 小时的日志
docker logs --since 2h auto_startup_test