配置Docker Desktop容器的自動(dòng)啟動(dòng)

默認(rèn)情況下,Docker Desktop里容器默認(rèn)是不會(huì)自動(dòng)隨Docker Desktop的啟動(dòng)而啟動(dòng)的,不過Docker提供了容器的重新啟動(dòng)策略。
運(yùn)行PowerShell通過下面的命令設(shè)置容器的自動(dòng)啟動(dòng)(記得把“<containerName>”換成需要自動(dòng)啟動(dòng)的容器的名字,并要注意容器名字是區(qū)分大小寫的):

docker update --restart=always <containerName>
圖1. 命令運(yùn)行示例

關(guān)于重啟策略說明如下:

  • no:缺省的設(shè)定,就是容器不會(huì)自動(dòng)啟動(dòng)
  • always:只要容器沒有被人為關(guān)閉,只要它停了就自動(dòng)啟動(dòng)它
  • unless-stopped:只要Docker的后臺(tái)關(guān)閉之前容器不是停止?fàn)顟B(tài)那么自動(dòng)啟動(dòng)該容器
  • on-failure:如果Docker的后臺(tái)重啟或者容器以非0代碼退出那么重啟該容器

以下是以上重啟策略內(nèi)容的參考來源:

Docker restart policies

There are following restart policies for Docker containers:

  • no: The default behavior is to not start containers automatically
  • always: Always restart a stopped container unless the container was stopped explicitly
  • unless-stopped: Restart the container unless the container was in stopped state before the Docker daemon was stopped (explained later)
  • on-failure: Restart the container if it exited with a non-zero exit code or if the docker daemon restarts
    As I mentioned, if you don't explicitly add a restart policy, it goes with "no", meaning containers won't be restarted automatically.

Beginner's Guide to Docker Restart Policy

常情情況下,我們需要讓Docker Desktop也自動(dòng)啟動(dòng),打開Docker Desktop,點(diǎn)擊右上角設(shè)置Setting齒輪圖標(biāo),然后在常規(guī)General卡片勾選登錄后啟動(dòng)Docker(Start Docker Desktop when you log in)然后點(diǎn)右下角應(yīng)用并重啟Apply & Restart按鈕。


圖2. 設(shè)置自動(dòng)啟動(dòng)Docker Desktop

注意,如此設(shè)置后,Docker Desktop只有在用戶登錄后才會(huì)啟動(dòng),如果需要做無人值守啟動(dòng),需要將Windows也設(shè)成自動(dòng)登錄,這里就不探討了。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容