常用基本命令

# 启动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具体参数,详见官方文档说明

PolicyResult
noDo 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次。
alwaysAlways 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-stoppedAlways 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守护程序停止之前容器就处于停止状态。
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐