1.創(chuàng)建容器時(shí)沒有添加參數(shù) --restart=always ,導(dǎo)致的后果是:當(dāng) Docker 重啟時(shí),容器未能自動(dòng)啟動(dòng)。
10年積累的成都做網(wǎng)站、成都網(wǎng)站制作經(jīng)驗(yàn),可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有陸良免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
docker container update --restart=always 容器名字
操作實(shí)例如下:
[root@localhost mnt]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46cdfc60b7a6 nginx "nginx -g 'daemon ..." About a minute ago Up 42 seconds 80/tcp n3
79d55a734c26 nginx "nginx -g 'daemon ..." About a minute ago Up 42 seconds 80/tcp n2
f7b2206c019d nginx "nginx -g 'daemon ..." About a minute ago Up 46 seconds 80/tcp n1
[root@localhost mnt]# docker container update --restart=always n1
n1
[root@localhost mnt]# systemctl restart docker
[root@localhost mnt]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46cdfc60b7a6 nginx "nginx -g 'daemon ..." 2 minutes ago Exited (0) 5 seconds ago n3
79d55a734c26 nginx "nginx -g 'daemon ..." 2 minutes ago Exited (0) 5 seconds ago n2
f7b2206c019d nginx "nginx -g 'daemon ..." 2 minutes ago Up 2 seconds 80/tcp n1
2.docker-compose 關(guān)機(jī)或者重啟docker同時(shí)重啟容器restart always的配置
眾所周知,存粹使用docker啟動(dòng)的話需要加–restart=always即可實(shí)現(xiàn)這個(gè)功能,而使用docker-compose的話在相關(guān)服務(wù)配置下加 restart: always 就行
version: '2'
services:
database:
build: ./MySQL/
command: mysqld --user=root --verbose
restart: always
environment:
MYSQL_DATABASE: "web_level3_sqli"
MYSQL_USER: "web_level3_sqli"
MYSQL_PASSWORD: "thisisasecurepassword123"
MYSQL_ROOT_PASSWORD: "root"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
web:
build: ./www/
restart: always
ports:
- "12000:80"
volumes:
- ./www/src:/var/www/html
links:
- database