本文介绍了在哪里放置php artisan migration命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务和任务运行良好

docker-compose.yml

version: '3.3'

networks:
  smstake:
    ipam:
      config:
        - subnet: 10.0.10.0/24

services:

    db:
        image: mysql:5.7
        networks:
          - smstake
        ports:
          - "3306:3306"
        volumes:
          - db_data:/var/lib/mysql
        environment:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_DATABASE: smstake
          MYSQL_USER: root
          MYSQL_PASSWORD: password
        deploy:
          mode: replicated
          placement:
            constraints:
              - node.role == manager
    app:

        image: smstake:latest
        ports:
          - 8000:80
        networks:
          - smstake

        command: docker-compose exec app php artisan migrate --seed
        deploy:
          mode: replicated
          replicas: 1
          placement:
            constraints:
              - node.role == manager
volumes:
    db_data:

这是用于生成映像的dockerfile

FROM alpine

ENV \
  APP_DIR="/app" \
  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

WORKDIR $APP_DIR

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

#CMD php artisan migrate:fresh
CMD php artisan serve --host=0.0.0.0 --port=$APP_PORT

尝试按注释添加到Dockerfile中,但没有解决问题

尝试添加docker-compose作为命令:php artisan migration:fresh

以前是在jenkins中进行此操作以使其正常工作,现在不想通过jenkins

docker-compose up -d --force-recreate --build

#Running commands on already running service
docker-compose exec -T app php artisan migrate:fresh --seed --force

推荐答案

这是我解决的方法.创建了一个名为 run.sh 的bash脚本,并添加了php artisan migrations命令以及php服务命令.

This is how I solved it .Created a bash script called run.sh and added the php artisan migrations commands followed by the php serve command.

run.sh

#!/bin/sh

cd /app
php artisan migrate:fresh --seed
php artisan serve --host=0.0.0.0 --port=$APP_PORT

入口点添加到Dockerfile中,最后删除 CMD ,这将运行所需的命令.

Added entrypoint to the Dockerfile removing the CMD in the end which will run the commands desired.

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

从docker-compose.yml中删除命令

Remove the command from the docker-compose.yml

这篇关于在哪里放置php artisan migration命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 08:25