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

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

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

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

  1. version: '3.4'
  2. networks:
  3. smstake:
  4. ipam:
  5. config:
  6. - subnet: 10.0.10.0/24
  7. services:
  8. db:
  9. image: MysqL:5.7
  10. networks:
  11. - smstake
  12. ports:
  13. - "3306"
  14. env_file:
  15. - configuration.env
  16. environment:
  17. MysqL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
  18. MysqL_DATABASE: ${DB_NAME}
  19. MysqL_USER: ${DB_USER}
  20. MysqL_PASSWORD: ${DB_PASSWORD}
  21. volumes:
  22. - MysqL_data:/var/lib/MysqL
  23. deploy:
  24. mode: replicated
  25. replicas: 1
  26. app:
  27. image: SMSTAKE_VERSION
  28. ports:
  29. - 8000:80
  30. networks:
  31. - smstake
  32. depends_on:
  33. - db
  34. deploy:
  35. mode: replicated
  36. replicas: 2

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

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

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

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

  1. | Cache cleared successfully.
  2. | Configuration cache cleared!
  3. | Dropped all tables successfully.
  4. | Migration table created successfully.
  5. |
  6. | In Connection.PHP line 664:
  7. |
  8. | sqlSTATE[42S02]: Base table or view not found: 1146 Table 'smstake.migratio
  9. | ns' doesn't exist (sql: insert into `migrations` (`migration`,`batch`) val
  10. | ues (2014_10_12_100000_create_password_resets_table,1))
  11. |
  12. |
  13. | In Connection.PHP line 452:
  14. |
  15. | sqlSTATE[42S02]: Base table or view not found: 1146 Table 'smstake.migratio
  16. | ns' doesn't exist
  17. |
  18. |
  19. | Laravel development server started: PHP 7.1.16 Development Server started at Thu Apr 5 07:02:22 2018
  20. | [Thu Apr 5 07:03:56 2018] 10.255.0.14:53744 [200]: /js/app.js
  21. | Cache cleared successfully.
  22. | Configuration cache cleared!
  23. | Dropped all tables successfully.
  24. | Migration table created successfully.
  25. | Migrating: 2014_10_12_000000_create_users_table
  26. | Migrated: 2014_10_12_000000_create_users_table
  27. | Migrating: 2014_10_12_100000_create_password_resets_table
  28. | Migrated: 2014_10_12_100000_create_password_resets_table
  29. | Migrating: 2018_01_11_235754_create_groups_table
  30. | Migrated: 2018_01_11_235754_create_groups_table
  31. | Migrating: 2018_01_12_085401_create_contacts_table
  32. | Migrated: 2018_01_12_085401_create_contacts_table
  33. | Migrating: 2018_01_12_140105_create_sender_ids_table
  34. | Migrated: 2018_01_12_140105_create_sender_ids_table
  35. | Migrating: 2018_02_06_152623_create_drafts_table
  36. | Migrated: 2018_02_06_152623_create_drafts_table
  37. | Migrating: 2018_02_21_141346_create_sms_table
  38. | Migrated: 2018_02_21_141346_create_sms_table
  39. | Seeding: UserTableSeeder
  40. | Laravel development server started: PHP 7.1.16 Development Server started at Thu Apr 5 07:03:23 2018
  41. | [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.

enter image description here

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

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

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

泊坞窗,compose.yml

  1. version: '3.4'
  2. networks:
  3. smstake:
  4. services:
  5. db:
  6. image: MysqL:5.7
  7. networks:
  8. - smstake
  9. ports:
  10. - "3306"
  11. environment:
  12. MysqL_ROOT_PASSWORD: password
  13. MysqL_DATABASE: smstake
  14. MysqL_USER: tara
  15. MysqL_PASSWORD: password
  16. volumes:
  17. - MysqL_data:/var/lib/MysqL
  18. deploy:
  19. mode: replicated
  20. replicas: 1
  21. placement:
  22. constraints:
  23. - node.role == manager
  24. app:
  25. image: 127.0.0.1:5000/myimage:latest
  26. ports:
  27. - 8000:80
  28. networks:
  29. - smstake
  30. depends_on:
  31. - db
  32. - migration
  33. deploy:
  34. mode: replicated
  35. replicas: 3
  36. migration:
  37. image: 127.0.0.1:5000/myimage:latest
  38. command: sh -xc "sleep 10 && pwd && PHP artisan migrate:fresh 2>&1"
  39. networks:
  40. - smstake
  41. depends_on:
  42. - db
  43. deploy:
  44. restart_policy:
  45. condition: on-failure
  46. mode: replicated
  47. replicas: 1
  48. placement:
  49. constraints:
  50. - node.role == manager
  51. volumes:
  52. MysqL_data:

Dockerfile

  1. FROM alpine
  2. ENV \
  3. APP_DIR="/project" \
  4. APP_PORT="80"
  5. # the "app" directory (relative to Dockerfile) containers your Laravel app...
  6. ##COPY app/ $APP_DIR
  7. # or we can make the volume in compose to say use this directory
  8. RUN apk update && \
  9. apk add curl \
  10. PHP7 \
  11. PHP7-opcache \
  12. PHP7-openssl \
  13. PHP7-pdo \
  14. PHP7-json \
  15. PHP7-phar \
  16. PHP7-dom \
  17. PHP7-curl \
  18. PHP7-mbstring \
  19. PHP7-tokenizer \
  20. PHP7-xml \
  21. PHP7-xmlwriter \
  22. PHP7-session \
  23. PHP7-ctype \
  24. PHP7-MysqLi \
  25. PHP7-pdo \
  26. PHP7-pdo_MysqL\
  27. && rm -rf /var/cache/apk/*
  28. RUN curl -sS https://getcomposer.org/installer | PHP -- \
  29. --install-dir=/usr/bin --filename=composer
  30. ##RUN cd $APP_DIR && composer install
  31. RUN mkdir /apps
  32. COPY ./project /apps
  33. RUN cd /apps && composer install
  34. WORKDIR /apps
  35. RUN chmod -R 775 storage
  36. RUN chmod -R 775 bootstrap
  37. copy ./run.sh /tmp
  38. CMD ["/tmp/run.sh"]

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

Migration

该应用程序也工作

App Working

猜你在找的Docker相关文章