docker怎么重启


重启 Docker 容器有两种方法:
1. 通过 Docker CLI 重启
docker restart
例如,要重启名为 "my-container" 的容器:
docker restart my-container
2. 通过 Docker API 重启
curl -X POST http://localhost:4243/containers//restart
Replace with the ID of the container you want to restart.
注意事项:
容器在重启后将从其当前状态重新启动。
容器内的数据不会受到影响。
容器所连接的卷将保持连接。
容器的 IP 地址和端口将保持不变。
正在运行的进程将被终止并重新启动。
使用 docker stop 后,必须先启动容器才能将其重新启动。
其他选项:
--time: 指定容器在重启前停止的时间(以秒为单位)。
--timeout: 指定容器重新启动前的超时时间(以秒为单位)。
--signal: 指定用于停止容器的信号(例如,"SIGTERM"、"SIGKILL")。
示例:
要在容器停止 5 秒后将其重新启动:
docker restart --time 5 my-container
要在容器停止 10 秒后将其重新启动,并使用 SIGKILL 信号:
docker restart --time 10 --signal SIGKILL my-container

相关文章