symfony - Symfony 4 应用程序与 Docker Compose 一起工作,但与 Docker Swarm 中断(没有登录,分析器损坏)
问题描述
我在本地使用Docker Compose :
- 应用程序容器:带有Symfony 4应用程序的Nginx和PHP-FPM
- PostgreSQL容器
- Redis容器
它在本地运行良好,但是当部署到开发Docker Swarm集群时,我无法登录 Symfony 应用程序。Swarm 堆栈与本地堆栈相同,除了安装在自己的服务器(不是 Docker 容器)上的PostgreSQL 。
使用profiler,我几乎总是得到以下错误:
未找到令牌 在数据库中未找到
令牌“2df1bb”。
当我显示var/log/dev.log
文件的内容时,我会收到有关我的登录尝试的这些行:
[2019-07-22 10:11:14] request.INFO: Matched route "app_login". {"route":"app_login","route_parameters":{"_route":"app_login","_controller":"App\\Controller\\SecurityController::login"},"request_uri":"http://dev.ip/public/login","method":"GET"} []
[2019-07-22 10:11:14] security.DEBUG: Checking for guard authentication credentials. {"firewall_key":"main","authenticators":1} []
[2019-07-22 10:11:14] security.DEBUG: Checking support on guard authenticator. {"firewall_key":"main","authenticator":"App\\Security\\LoginFormAuthenticator"} []
[2019-07-22 10:11:14] security.DEBUG: Guard authenticator does not support the request. {"firewall_key":"main","authenticator":"App\\Security\\LoginFormAuthenticator"} []
[2019-07-22 10:11:14] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
我可能在这里发现唯一有用的是Guard authenticator does not support the request.
消息,但我不知道从那里搜索什么。
更新:
这是我的docker-compose.dev.yml
(删除了 redis 容器并更改了应用程序环境变量):
version: "3.7"
networks:
web:
driver: overlay
services:
# Symfony + Nginx
app:
image: "registry.gitlab.com/my-image"
deploy:
replicas: 2
restart_policy:
condition: on-failure
networks:
- web
ports:
- 80:80
environment:
APP_ENV: dev
DATABASE_URL: pgsql://user:pass@0.0.0.0/my-db
MAILER_URL: gmail://user@gmail.com:pass@localhost
这是Dockerfile.dev
用于在开发服务器上构建应用程序映像的方法:
# Base image
FROM php:7.3-fpm-alpine
# Source code into:
WORKDIR /var/www/html
# Import Symfony + Composer
COPY --chown=www-data:www-data ./symfony .
COPY --from=composer /usr/bin/composer /usr/bin/composer
# Alpine Linux packages + PHP extensions
RUN apk update && apk add \
supervisor \
nginx \
bash \
postgresql-dev \
wget \
libzip-dev zip \
yarn \
npm \
&& apk --no-cache add pcre-dev ${PHPIZE_DEPS} \
&& pecl install redis \
&& docker-php-ext-enable redis \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo_pgsql \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip \
&& composer install \
--prefer-dist \
--no-interaction \
--no-progress \
&& yarn install \
&& npm rebuild node-sass \
&& yarn encore dev \
&& mkdir -p /run/nginx
# Nginx conf + Supervisor entrypoint
COPY ./dev.conf /etc/nginx/conf.d/default.conf
COPY ./.htpasswd /etc/nginx/.htpasswd
COPY ./supervisord.conf /etc/supervisord.conf
EXPOSE 80 443
ENTRYPOINT /usr/bin/supervisord -c /etc/supervisord.conf
更新 2:
我pull
编辑了我的Docker映像并仅使用docker-compose.dev.yml
(没有docker-compose.local.yml
我在本地使用的)运行应用程序。我已经可以登录了,一切正常。
所以......它适用于本地Docker Compose ,但不适用于远程服务器上的Docker Swarm 。
更新 3:
我让开发服务器离开Swarm 集群并使用Docker Compose启动服务。有用。
问题是关于从Compose到Swarm。我创建了一个问题:docker/swarm #2956
解决方案
也许这不是您的具体情况,但它可以帮助一些在使用 Docker Swarm 时遇到问题的用户,这些问题在 Docker Compose 中不存在。
我已经为这个问题奋斗了一个多星期。我发现 Docker Compose 的默认网络使用桥接驱动程序,而 Docker Swarm 使用Overlay。
后来,我在Postgres Docker 映像存储库的警告部分中读到,覆盖网络中的 IPVS 连接超时存在问题,它参考了此博客以获取解决方案。
我尝试使用第一个选项并将endpoint_mode设置更改为dnsrr
我的docker-compose.yml
文件中:
db:
image: postgres:12
# Others settings ...
deploy:
endpoint_mode: dnsrr
请记住,有一些警告(在博客中提到)需要考虑。但是,您可以尝试其他选项。
同样在这个问题中,您可能会发现一些有用的东西,因为他们面临同样的问题。
推荐阅读
- docker - 如何使用 docker 容器作为同一网络中其他容器的路由器
- ios - 缩放标签的字体大小或旋转标签?(迅速)
- html - 如何通过调整大小将图像叠加在视频之上?
- python - Python/ Pandas CSV 解析表单响应
- flutter - AppLifeCycleState.detached 未被调用
- c - 获取链接器符号的虚拟内存地址(vma)
- amazon-web-services - terraform 中的 ssh 密钥对
- python - 使用日期周和数据行内容重命名多列
- csv - 处理 CSV 数据:用逗号分隔数据
- bash - 处理文本文件中的数据并转换为 csv