常用基本命令
# 启动docker
systemctl start docker
# 停止dokcer
systemctl stop docker
# 查看docker状态
systemctl status docker
# 重启docker
systemctl restart docker
# 设置docker 开机自启
systemctl enable docker
# 查看docker 版本
docker version
# 查看docker 镜像
docker images
# 查看docker 运行列表
docker ps
# 查看docker (运行、停止)
docker ps -aq
# 删除容器
docker rm -f 容器ID/容器名称(CONTAINER ID/NAMES)
# 删除多个容器(空格隔开)
docker rm -f 容器ID/容器名称 容器ID/容器名称 ...
# 删除全部容器
docker rm -f $(docker ps -aq)
设置docker开机自启
systemctl enable docker
设置容器自启
1. 创建容器时设置:
docker run -d --restart=always --name 容器名称 镜像名称
# 例如:
docker run --restart=always 56f0b18af626
2. 更新已有容器设置:
docker update --restart=always 容器ID
# 例如:
docker update --restart=always 56f0b18af626
–restart具体参数,详见官方文档说明文章来源地址https://www.toymoban.com/news/detail-508272.html
Policy | Result |
---|---|
no | Do not automatically restart the container when it exits. This is the default. 默认设置,容器退出时不重启容器。 |
on-failure[:max-retries] | Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts. 在容器非正常退出时重启容器,最多重启max-retries次。 |
always | Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container. 总是重启容器。 |
unless-stopped | Always restart the container regardless of the exit status, including on daemon startup, except if the container was put into a stopped state before the Docker daemon was stopped. 总是重启容器,除非在Docker守护程序停止之前容器就处于停止状态。 |
文章来源:https://www.toymoban.com/news/detail-508272.html
到了这里,关于docker常用命令及设置开机自启的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!