Symfony 4应用程序可与Docker Compose一起使用,但会与Docker Swarm一起中断(未登录,分析器损坏) [英] Symfony 4 app works with Docker Compose but breaks with Docker Swarm (no login, profiler broken)

查看:145
本文介绍了Symfony 4应用程序可与Docker Compose一起使用,但会与Docker Swarm一起中断(未登录,分析器损坏)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地使用 Docker Compose


  • app 容器: Nginx &具有 Symfony 4 应用程序的 PHP-FPM

  • PostgreSQL 容器

  • Redis 容器

  • app container: Nginx & PHP-FPM with a Symfony 4 app
  • PostgreSQL container
  • Redis container

在本地运行良好,但在部署到开发中时使用 Docker Swarm 群集,我无法登录Symfony应用。
Swarm堆栈与本地堆栈相同,但 PostgreSQL 除外,它安装在自己的服务器(不是Docker容器)上。

It works great locally but when deployed to the development Docker Swarm cluster, I can't login to the Symfony app. The Swarm stack is the same as local, except for PostgreSQL which is installed on its own server (not a Docker container).

使用 profiler ,我几乎总是收到以下错误:

Using the profiler, I nearly always get the following error:


未找到令牌

在数据库中找不到令牌 2df1bb。

Token not found
Token "2df1bb" was not found in the database.

当我显示以下内容时 var / log / dev.log 文件,我得到以下有关登录尝试的信息:

When I display the content of the var/log/dev.log file, I get these lines about my login attempts:

[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验证者不支持该请求。消息,但我不知道从那里进行什么搜索。

The only thing I may find useful here is the Guard authenticator does not support the request. message, but I have no idea what do search from there.

更新:

这是我的 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 用于在开发服务器上构建 app 映像:

Here is the Dockerfile.dev used to build the app image on development servers:

# 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






UPDATE 2:

pull 提取了我的 Docker 图像,仅使用 docker-compose.dev.yml (没有在本地使用过的 docker-compose.local.yml ) 。我已经能够登录,一切正常。


UPDATE 2:
I pulled my Docker images and ran the application using only the docker-compose.dev.yml (without the docker-compose.local.yml that I'd use too locally). I have been able to login, everything is okay.

所以...它与 Docker Compose local 一起使用,但不在远程服务器上的 Docker Swarm 中。

So... It works with Docker Compose locally, but not in Docker Swarm on a remote server.

更新3:

我使开发服务器离开了 Swarm集群,并使用 Docker Compose 启动了服务。

UPDATE 3:
I made the dev server leave the Swarm cluster and started the services using Docker Compose. It works.

问题是有关从撰写 Swarm 。我创建了一个问题: docker / swarm#2956

The issue is about going from Compose to Swarm. I created an issue: docker/swarm #2956

推荐答案

也许这不是您的特定情况,但是它可以帮助使用Docker Swarm时出现问题的用户(Docker Compose中不存在)。

Maybe it's not your specific case, but it could help some user who have problems using Docker Swarm which are not present in Docker Compose.

我已经为这个问题解决了一个多星期。我发现Docker Compose的默认网络使用 bridge 驱动程序,而Docker Swarm使用 Overlay

I've been fighting this issue for over a week. I found that the default network for Docker Compose uses the bridge driver and Docker Swarm uses Overlay.

稍后,我在 Postgres Docker镜像存储库中的 Caveats 部分覆盖网络中的IPVS连接超时,它引用此博客以了解解决方案。

Later, I read in the Caveats section in the Postgres Docker image repo that there's a poblem with the IPVS connection timeouts in overlay networks and it refers to this blog for solutions.

我尝试第一种方法,并更改了 docker-compose.yml 文件中,将noreferrer> endpoint_mode 设置为 dnsrr

I try with the first option and changed the endpoint_mode setting to dnsrr in my docker-compose.yml file:

db:
    image: postgres:12
    # Others settings ...
    deploy:
        endpoint_mode: dnsrr

请记住,有一些注意事项(博客中已提及)需要考虑。但是,您可以尝试其他选项。

Keep in mind that there are some caveats (mentioned in the blog) to consider. However, you could try the other options.

也在这个问题,也许您会发现一些有用的东西,因为他们面临同样的问题。

Also in this issue maybe you find something useful as they faced the same problem.

这篇关于Symfony 4应用程序可与Docker Compose一起使用,但会与Docker Swarm一起中断(未登录,分析器损坏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆