常用基本命令
# 啟動docker
systemctl start docker
# 停止dokcer
systemctl stop docker
# 查看docker狀態(tài)
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. 創(chuàng)建容器時設置:
docker run -d --restart=always --name 容器名稱 鏡像名稱
# 例如:
docker run --restart=always 56f0b18af626
2. 更新已有容器設置:
docker update --restart=always 容器ID
# 例如:
docker update --restart=always 56f0b18af626
–restart具體參數(shù),詳見官方文檔說明文章來源地址http://www.zghlxwxcb.cn/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守護程序停止之前容器就處于停止狀態(tài)。 |
文章來源:http://www.zghlxwxcb.cn/news/detail-508272.html
到了這里,關于docker常用命令及設置開機自啟的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!