一个 PHP-FPM 容器(7.2),经典 LAPP 堆栈的成员,在启动时正确公开端口 9000docker-compose
但当由 Docker Swarm 启动时没有任何反应。我应该提到容器正在运行(见下面的输出)并且我可以在其上启动 TTY bash。
因此,使用 时docker-compose
,Web 应用程序功能齐全,但使用 Swarm 时,Apache 会发出 503 服务不可用。使用不同引擎的测试之间没有任何变化。您对这种行为有任何线索吗?
docker-compose.yml
version: '3.5'
services:
postgres:
env_file: ./.env
image: "postgres:9.5.24"
volumes:
- database:/var/lib/postgresql/data
networks:
- internal
adminer:
image: adminer
networks:
- internal
- traefik-public
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.adminer.rule=Host(`adminer.example.com`)"
- "traefik.http.routers.adminer.entrypoints=websecure"
- "traefik.http.routers.adminer.tls.certresolver=letsencryptresolver"
- "traefik.http.services.adminer.loadbalancer.server.port=8080"
- "traefik.port=80"
apache:
env_file: ./.env
image: visio_rdv_apache:latest
build:
context: docker/images/apache2.4
dockerfile: Dockerfile
args:
UID: ${HOST_UID}
ROOT_URL: ${ROOT_URL}
ports:
- 8000:80
environment:
FPM_HOST: php:9000
ROOT_URL: ${ROOT_URL}
volumes:
- ${LOGS_DIR}/apache/:/var/log/httpd/
- ${RELATIVE_APP_PATH}:/var/www/html
links:
- postgres
- php
networks:
- internal
- traefik-public
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.visio_rdv.rule=Host(`test.example.com`)"
- "traefik.http.routers.visio_rdv.entrypoints=websecure"
- "traefik.http.routers.visio_rdv.tls.certresolver=letsencryptresolver"
- "traefik.http.services.visio_rdv.loadbalancer.server.port=80"
- "traefik.port=80"
php:
env_file: .env
links:
- ftp
image: visio_rdv_php:latest
build:
context: docker/images/php
dockerfile: Dockerfile
args:
UID: ${HOST_UID}
TIMEZONE: ${TIMEZONE}
PROXY: ${http_proxy}
volumes:
- ftp_data:/var/www/ftp:rw
- ${RELATIVE_APP_PATH}:/var/www/html
networks:
- internal
ftp:
env_file: .env
image: "fauria/vsftpd:latest"
ports:
- "9520:20"
- "9521:21"
- "21100-21110:21100-21110"
environment:
FTP_USER: ${FTP_USER}
FTP_PASS: ${FTP_PASS}
PASV_MIN_PORT: 21100
PASV_MAX_PORT: 21100
volumes:
- ftp_data:/home/vsftpd/${AUTOMATION_CLIENT_NAME}:rw
networks:
- internal
volumes:
ftp_data:
database:
networks:
traefik-public:
external: true
internal:
external: false
使用 Docker Swarm
Apache 日志:
[Wed Aug 04 07:35:16.382246 2021] [proxy:error] [pid 11] (111)Connection refused: AH00957: FCGI: attempt to connect to 10.0.4.93:9000 (*) failed
[Wed Aug 04 07:35:16.382314 2021] [proxy_fcgi:error] [pid 11] [client 10.0.0.2:1035] AH01079: failed to make connection to backend: php, referer: http://test.example.com/
Swarm 服务列表:
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
um2txtpz8534 traefik_reverse-proxy replicated 1/1 traefik:v2.4
ahf7uukapxbr my_stack_adminer replicated 1/1 adminer:latest
ue8qekmg0ff0 my_stack_apache replicated 1/1 my_stack_apache:latest my_stack*:8000->80/tcp
x9igaslhsx11 my_stack_ftp replicated 1/1 fauria/vsftpd:latest *:9520-9521->20-21/tcp, *:21100-21110->21100-21110/tcp
jpk4qzqs1tfx my_stack_php replicated 1/1 my_stack_php:latest
ih67rh82vp9e my_stack_postgres replicated 1/1 postgres:9.5.24
我尝试将其添加net-tools
到 PHP 映像中,以便手动测试与 的连接nc
。结果相同,php
容器实例 IP 被正确解析,但任何到端口 9000 的 TCP 连接都被拒绝。
我使用了很多环境变量,为了弥补 Swarm 缺少的功能,我使用docker-compose config
命令输出来生成完整的docker-compose.yml
文件。
和docker-compose
Name Command State Ports
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
my_stack_adminer_1 entrypoint.sh docker-php-e ... Up 8080/tcp
my_stack_apache_1 /bin/sh -c apachectl -D FO ... Up 0.0.0.0:8000->80/tcp
my_stack_ftp_1 /usr/sbin/run-vsftpd.sh Up 0.0.0.0:9520->20/tcp, 0.0.0.0:9521->21/tcp, 0.0.0.0:21100->21100/tcp, 0.0.0.0:21101->21101/tcp, 0.0.0.0:21102->21102/tcp,
0.0.0.0:21103->21103/tcp, 0.0.0.0:21104->21104/tcp, 0.0.0.0:21105->21105/tcp, 0.0.0.0:21106->21106/tcp, 0.0.0.0:21107->21107/tcp,
0.0.0.0:21108->21108/tcp, 0.0.0.0:21109->21109/tcp, 0.0.0.0:21110->21110/tcp
my_stack_php_1 php-fpm -R -F Up 9000/tcp
my_stack_postgres_1 docker-entrypoint.sh postgres Up 5432/tcp
答案1
- 您是怎样进行构建的?
Swarm 与 docker-compose 不同:“部署就是部署“ - 和不是一个构建!(您需要在部署图像之前构建图像 - 并且(可能可用的)组合图像可能无法满足要求......)
和:
docker stack deploy -c your-compose-style-code.yml <name-of-your-swarm>
您正在将现有图像部署到选定的群中(它可能使用您之前通过 docker-compose 构建的图像……
... Swarm 中的另一个主题是网络:您需要了解网络范围(集群或 Swarm 范围覆盖 - 或“内部”网络的范围,以连接“命名空间”的选定服务,就像您在 compose 中所做的那样...)
...然后,当然,有状态部分(数据库、用户可能上传的文件)的卷需要以不同的方式进行管理(从 NFS 到 glusterFS 到 Galera 到 linbit/LINSTOR...或者 cockroachDB 只是举几个例子...),因为管弦乐队无状态部分的容器现在分布在许多不同的节点上..
- 有时在你的群体中添加“搬运工”是个好主意 https://www.portainer.io/solutions/docker...