skip to Main Content

I have a laravel 8 project created with composer. Then I added laravel sail by composer require laravel/sail and then executed command php artisan sail:install.
After sail up command, only mysql container was created and everything works well. But now I want to add redis to my docker container. How can I do this? I have no knowledge with Docker but laravel sail has made it very easy to use Docker. I want to add redis with the help of laravel sail. Is there any way to do that?

3

Answers


  1. you can edit docker-compose.yml

    In the services

    laravel.test:
    ...
            depends_on:
                - mysql
                - redis
    ...
    
        redis:
            image: 'redis:alpine'
            ports:
                - '${FORWARD_REDIS_PORT:-6379}:6379'
            volumes:
                - 'sailredis:/data'
            networks:
                - sail
            healthcheck:
              test: ["CMD", "redis-cli", "ping"]
    

    then finally, in volumes:

    volumes:
        sailmysql:
            driver: local
        sailredis:
            driver: local
    
    

    You may also can start a fresh new project with

    curl -s "https://laravel.build/example-app?with=mysql,redis" | bash
    
    

    then refer the generated docker-compose.yml

    after you edit, save it then run ./vendor/bin/sail build then only saild up -d

    Login or Signup to reply.
  2. I know it is not the best solution but I think it’s so easy.
    Update your docker-compose.yml file using following lines:

    version: '3'
    services:
        laravel.test:
            build:
                context: ./vendor/laravel/sail/runtimes/8.0
                dockerfile: Dockerfile
                args:
                    WWWGROUP: '${WWWGROUP}'
            image: sail-8.0/app
            extra_hosts:
                - 'host.docker.internal:host-gateway'
            ports:
                - '${APP_PORT:-80}:80'
            environment:
                WWWUSER: '${WWWUSER}'
                LARAVEL_SAIL: 1
                XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
                XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
            volumes:
                - '.:/var/www/html'
            networks:
                - sail
            depends_on:
                - mysql
                - redis
        mysql:
            image: 'mysql:8.0'
            ports:
                - '${FORWARD_DB_PORT:-3306}:3306'
            environment:
                MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
                MYSQL_DATABASE: '${DB_DATABASE}'
                MYSQL_USER: '${DB_USERNAME}'
                MYSQL_PASSWORD: '${DB_PASSWORD}'
                MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
            volumes:
                - 'sailmysql:/var/lib/mysql'
            networks:
                - sail
            healthcheck:
                test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
                retries: 3
                timeout: 5s
        redis:
            image: 'redis:alpine'
            ports:
                - '${FORWARD_REDIS_PORT:-6379}:6379'
            volumes:
                - 'sailredis:/data'
            networks:
                - sail
            healthcheck:
                test: ["CMD", "redis-cli", "ping"]
                retries: 3
                timeout: 5s
    networks:
        sail:
            driver: bridge
    volumes:
        sailmysql:
            driver: local
        sailredis:
            driver: local
    
    Login or Signup to reply.
  3. You can just issue the command php artisan sail:install again

    Now select the services you need and separate them with ,

    So for example 0, 3, 7
    This will update your docker-compose.yml file and add the lines for MySQL, Redis, Mailhog. It might overwrite some of your old settings though!

    Once you start sail again it will pull the services and you’re good to go.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search