laraveldockerlaravel-sail

Add new service using laravel sail


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?


Solution

  • you can edit docker-compose.yml

    In 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 can also 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 sail up -d