Skip to content

Instantly share code, notes, and snippets.

@lucenarenato
Last active October 14, 2024 17:37
Show Gist options
  • Save lucenarenato/deef20cc7e4806a8f20c4287098f8c37 to your computer and use it in GitHub Desktop.
Save lucenarenato/deef20cc7e4806a8f20c4287098f8c37 to your computer and use it in GitHub Desktop.
Laravel Schedule doesn't work on my docker container

Dockerfile

FROM devilbox/php-fpm-8.1:latest

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    git \
    curl \
    nano \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libmcrypt-dev \
    libgd-dev \
    jpegoptim optipng pngquant gifsicle \
    libonig-dev \
    libxml2-dev \
    zip \
    sudo \
    unzip \
    npm \
    nodejs \
    cron


# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Get latest Composers
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user


RUN touch crontab.tmp
RUN echo '* * * * * cd /var/www && php artisan schedule:run >> /dev/null 2>&1' >> crontab.tmp
RUN crontab crontab.tmp
RUN rm -rf crontab.tmp


# Set working directory
WORKDIR /var/www

USER $user

docker-compose.yml

version: "3.7"
services:
    app:
        build:
            args:
                user: creativecloud
                uid: 1000
            context: ./
            dockerfile: Dockerfile
        image: ufree
        container_name: ufree-app
        restart: unless-stopped
        working_dir: /var/www/
        volumes:
            - ./:/var/www
            - ./docker-compose/php/conf/custom.php.ini:/usr/local/etc/php/conf.d/custom.ini

        networks:
            - ufree
        depends_on:
            - db
            - cache

    db:
        image: mysql:8.0
        container_name: ufree-db
        restart: unless-stopped
        volumes:
            - ./data/mysql:/var/lib/mysql/
        environment:
            MYSQL_DATABASE: ${DB_DATABASE}
            MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
            MYSQL_PASSWORD: ${DB_PASSWORD}
            MYSQL_USER: ${DB_USERNAME}
            SERVICE_TAGS: dev
            SERVICE_NAME: mysql
        networks:
            - ufree

    phpmyadmin:
        image: 'phpmyadmin:latest'
        container_name: ufree-phpmyadmin
        ports:
            - 8081:80
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            UPLOAD_LIMIT: 300M
        links:
            - "db:db"
        depends_on:
            - db
        networks:
            - ufree

    nginx:
        image: nginx:alpine
        container_name: ufree-nginx
        restart: unless-stopped
        ports:
            - 8080:80
        volumes:
            - ./:/var/www
            - ./docker-compose/nginx:/etc/nginx/conf.d/
        networks:
            - ufree

    cache:
        image: redis:alpine
        container_name: ufree-redis
        ports:
            - "6382:6379"
        volumes:
            - ./data/redis:/data
        networks:
            - ufree

networks:
    ufree:
        driver: bridge
@lucenarenato
Copy link
Author

Personaly I am using hosts crontab with line like that* * * * * * dockeruser docker exec laravel-app-container-name /usr/local/bin/php /var/www/artisan shedule:run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment