我有一台用作 NAS 的 PC,它运行 NextCloud 实例,作为一组通过 docker-compose 管理的 docker 容器,我将在下面提供 docker-compose.yml。我的问题是,即使我的所有容器都配置为“restart: always”,如果我重新启动 NAS,只有一个容器会尝试启动,并且实际上会无限期地保持“正在重新启动”状态。例如,我在进行一些更新后重新启动了我的 NAS,以下是输出$ docker ps
:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5679fcfe9174 jrcs/letsencrypt-nginx-proxy-companion "/bin/bash /app/entr…" 5 weeks ago Restarting (1) 18 seconds ago nextcloud-letsencrypt
如果我尝试使用启动所有容器,$ docker-compose up -d
我会得到以下输出:
Starting nextcloud-mariadb ... error
Starting nextcloud-proxy ...
ERROR: for nextcloud-mariadb Cannot start service db: container is marked for removal and cannot be started
Starting nextcloud-proxy ... error
ERROR: for nextcloud-proxy Cannot start service proxy: driver failed programming external connectivity on endpoint nextcloud-proxy (a73acdc99f7fb693a231ffd3b9cbb6d69a96176d41511c259c82a00dfab704a5): Error starting userland proxy: listen tcp 0.0.0.0:443: bind: address already in use
ERROR: for db Cannot start service db: container is marked for removal and cannot be started
ERROR: for proxy Cannot start service proxy: driver failed programming external connectivity on endpoint nextcloud-proxy (a73acdc99f7fb693a231ffd3b9cbb6d69a96176d41511c259c82a00dfab704a5): Error starting userland proxy: listen tcp 0.0.0.0:443: bind: address already in use
ERROR: Encountered errors while bringing up the project.
事实上,如果我使用以下方法查找开放端口,$ sudo netstat -tulpn | grep LISTEN
我会得到类似的结果:
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 1341/systemd-resolv
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1457/sshd: /usr/sbi
tcp6 0 0 :::80 :::* LISTEN 2500/docker-proxy
tcp6 0 0 :::22 :::* LISTEN 1457/sshd: /usr/sbi
tcp6 0 0 :::443 :::* LISTEN 2476/docker-proxy
在终止两个“docker-proxy”进程并通过重新启动 Docker 守护程序后,$ sudo systemctl restart docker
我终于启动并运行了所有容器(包括另一个配置为“restart: always”但不是 NextCloud 实例的一部分的容器)。
我的问题是:如何让 Docker 在重启后自动启动所有容器无需手动终止两个“docker-proxy”实例并重新启动docker守护程序?我使用的操作系统是Ubuntu Server 20.04.1 LTS,我的Docker版本是19.03.13,内部版本4484c46d9d。这是我的NextCloud实例的docker-compose.yml:
version: '3'
services:
proxy:
image: jwilder/nginx-proxy:alpine
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
container_name: nextcloud-proxy
networks:
- nextcloud_network
ports:
- 80:80
- 443:443
volumes:
- ./proxy/conf.d:/etc/nginx/conf.d:rw
- ./proxy/vhost.d:/etc/nginx/vhost.d:rw
- ./proxy/html:/usr/share/nginx/html:rw
- ./proxy/certs:/etc/nginx/certs:ro
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
restart: always
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nextcloud-letsencrypt
depends_on:
- proxy
networks:
- nextcloud_network
volumes:
- ./proxy/certs:/etc/nginx/certs:rw
- ./proxy/vhost.d:/etc/nginx/vhost.d:rw
- ./proxy/html:/usr/share/nginx/html:rw
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
restart: always
db:
image: mariadb
container_name: nextcloud-mariadb
networks:
- nextcloud_network
volumes:
- db:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
environment:
- MYSQL_ROOT_PASSWORD=[redacted]
- MYSQL_PASSWORD=[redacted]
- MYSQL_DATABASE=[redacted]
- MYSQL_USER=[redacted]
restart: always
app:
image: nextcloud:latest
container_name: nextcloud-app
networks:
- nextcloud_network
depends_on:
- letsencrypt
- proxy
- db
volumes:
- nextcloud-data:/var/www/html
- /etc/localtime:/etc/localtime:ro
environment:
- VIRTUAL_HOST=[redacted], [redacted]
- LETSENCRYPT_HOST=[redacted], [redacted]
- LETSENCRYPT_EMAIL=[redacted]
restart: always
volumes:
nextcloud-data:
external: true
db:
networks:
nextcloud_network: