未在管理器节点中运行时,Docker服务laravel应用程序未运行

前端之家收集整理的这篇文章主要介绍了未在管理器节点中运行时,Docker服务laravel应用程序未运行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

泊坞窗,compose.yml
这是我的docker-compose文件,用于使用docker-stack在多个实例中部署服务.正如您所看到的那样,应用程序服务是在2个节点中运行的laravel和其中一个节点中的数据库(mysql).@H_502_3@

完整代码库:
https://github.com/taragurung/Ci-CD-docker-swarm@H_502_3@

@H_502_3@

version: '3.4'
networks:
  smstake:   
    ipam:
      config:
        - subnet: 10.0.10.0/24

services:
    db:
        image: MysqL:5.7
        networks:
          - smstake
        ports:
          - "3306"
        env_file:
          - configuration.env
        environment:
          MysqL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
          MysqL_DATABASE: ${DB_NAME}
          MysqL_USER: ${DB_USER}
          MysqL_PASSWORD: ${DB_PASSWORD}
        volumes:
          - MysqL_data:/var/lib/MysqL
        deploy:
          mode: replicated
          replicas: 1

    app:
        image: SMSTAKE_VERSION
        ports:
          - 8000:80
        networks:
          - smstake
        depends_on:
          - db
        deploy:
          mode: replicated
          replicas: 2

我面临的问题.
1.虽然在检查服务日志时服务处于运行状态,但我可以看到仅在一个节点中成功迁移而在另一个节点中没有运行.请参阅下面的日志@H_502_3@

>当我使应用程序服务仅在管理器节点中运行限制时,应用程序运行良好.我可以登录页面并执行所有操作但是当我使用复制品在任何节点中运行应用程序服务时,登录页面显示但是当尝试登录重定向到NOT FOUND页面@H_502_3@

尝试在3个节点上运行时,这是完整日志. Bellow是在2个节点上运行时的示例.您可以详细了解迁移问题
https://pastebin.com/wqjxSnv2@H_502_3@

使用泊坞窗服务日志检查服务日志< smstake_app>@H_502_3@

@H_502_3@

| Cache cleared successfully.
    | Configuration cache cleared!
    | Dropped all tables successfully.
    | Migration table created successfully.
    | 
    | In Connection.PHP line 664:
    |                                                                                
    |   sqlSTATE[42S02]: Base table or view not found: 1146 Table 'smstake.migratio  
    |   ns' doesn't exist (sql: insert into `migrations` (`migration`,`batch`) val  
    |   ues (2014_10_12_100000_create_password_resets_table,1))                     
    |                                                                                
    | 
    | In Connection.PHP line 452:
    |                                                                                
    |   sqlSTATE[42S02]: Base table or view not found: 1146 Table 'smstake.migratio  
    |   ns' doesn't exist                                                            
    |                                                                                
    | 
    | Laravel development server started: PHP 7.1.16 Development Server started at Thu Apr  5 07:02:22 2018
    | [Thu Apr  5 07:03:56 2018] 10.255.0.14:53744 [200]: /js/app.js



    | Cache cleared successfully.
    | Configuration cache cleared!
    | Dropped all tables successfully.
    | Migration table created successfully.
    | Migrating: 2014_10_12_000000_create_users_table
    | Migrated:  2014_10_12_000000_create_users_table
    | Migrating: 2014_10_12_100000_create_password_resets_table
    | Migrated:  2014_10_12_100000_create_password_resets_table
    | Migrating: 2018_01_11_235754_create_groups_table
    | Migrated:  2018_01_11_235754_create_groups_table
    | Migrating: 2018_01_12_085401_create_contacts_table
    | Migrated:  2018_01_12_085401_create_contacts_table
    | Migrating: 2018_01_12_140105_create_sender_ids_table
    | Migrated:  2018_01_12_140105_create_sender_ids_table
    | Migrating: 2018_02_06_152623_create_drafts_table
    | Migrated:  2018_02_06_152623_create_drafts_table
    | Migrating: 2018_02_21_141346_create_sms_table
    | Migrated:  2018_02_21_141346_create_sms_table
    | Seeding: UserTableSeeder
    | Laravel development server started: PHP 7.1.16 Development Server started at Thu Apr  5 07:03:23 2018
    | [Thu Apr  5 07:03:56 2018] 10.255.0.14:53742 [200]: /css/app.css

I don’t know if its due to migration problem or what. Sometime I can
login and after few time I get redirected to Not found page again when
clicking on the link inside dashboard.@H_502_3@

enter image description here

最佳答案
所以我运行了你的服务,发现了一些问题.@H_502_3@

> MysqL中docker-compose.yml中的用户不同.这可能仅仅是为了发布目的
>在Dockerfile中,您使用了ENTRYPOINT,这也导致在迁移服务上运行相同的命令.我把它改成了CMD
>您没有在与MysqL数据库相同的网络中运行迁移服务.所以MysqL无法从同一个地方访问.@H_502_3@

这是我使用的最终撰写文件@H_502_3@

泊坞窗,compose.yml@H_502_3@

@H_502_3@

version: '3.4'

networks:
  smstake:


services:
    db:
        image: MysqL:5.7
        networks:
          - smstake
        ports:
          - "3306"
        environment:
          MysqL_ROOT_PASSWORD: password
          MysqL_DATABASE: smstake
          MysqL_USER: tara
          MysqL_PASSWORD: password
        volumes:
          - MysqL_data:/var/lib/MysqL
        deploy:
          mode: replicated
          replicas: 1
          placement:
            constraints:
              - node.role == manager


    app:
        image: 127.0.0.1:5000/myimage:latest
        ports:
          - 8000:80
        networks:
          - smstake
        depends_on:
          - db
          - migration
        deploy:
          mode: replicated
          replicas: 3

    migration:
        image: 127.0.0.1:5000/myimage:latest
        command: sh -xc "sleep 10 && pwd && PHP artisan migrate:fresh 2>&1"
        networks:
          - smstake
        depends_on:
          - db
        deploy:
          restart_policy:
            condition: on-failure
          mode: replicated
          replicas: 1
          placement:
            constraints:
              - node.role == manager


volumes:
    MysqL_data:

Dockerfile@H_502_3@

@H_502_3@

FROM alpine

ENV \
  APP_DIR="/project" \
  APP_PORT="80"

# the "app" directory (relative to Dockerfile) containers your Laravel app...
##COPY app/ $APP_DIR
# or we can make the volume in compose to say use this directory

RUN apk update && \
    apk add curl \
    PHP7 \
    PHP7-opcache \
    PHP7-openssl \
    PHP7-pdo \
    PHP7-json \
    PHP7-phar \
    PHP7-dom \
    PHP7-curl \
    PHP7-mbstring \
    PHP7-tokenizer \
    PHP7-xml \
    PHP7-xmlwriter \
    PHP7-session \
    PHP7-ctype \
    PHP7-MysqLi \
    PHP7-pdo \
    PHP7-pdo_MysqL\
    && rm -rf /var/cache/apk/*

RUN curl -sS https://getcomposer.org/installer | PHP -- \
  --install-dir=/usr/bin --filename=composer

##RUN cd $APP_DIR && composer install

RUN mkdir /apps
COPY ./project /apps
RUN cd /apps && composer install

WORKDIR /apps

RUN chmod -R 775 storage
RUN chmod -R 775 bootstrap

copy ./run.sh /tmp
CMD ["/tmp/run.sh"]

然后再次运行该服务.然后迁移就好了@H_502_3@

Migration

@H_502_3@

该应用程序也工作@H_502_3@

App Working

猜你在找的Docker相关文章