Add new service using laravel sail
Asked Answered
T

5

9

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?

Tonry answered 14/4, 2021 at 18:34 Comment(0)
A
17

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

Airdrop answered 16/5, 2021 at 3:13 Comment(1)
The command php artisan sail:add service now also works. So php artisan sail:add redis for Redis if not installed earlier.Systematics
C
12

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.

Cull answered 18/11, 2021 at 14:50 Comment(0)
C
4

just run the command php artisan sail:add <service>

Cachucha answered 4/1, 2024 at 23:53 Comment(0)
S
0

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
Stearic answered 8/10, 2021 at 17:15 Comment(0)
B
0
php artisan sail:add

Brings up the selector for the available services. Select with space then enter.

Laravel Sail Docs

Bursa answered 23/5, 2024 at 13:15 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.