skip to Main Content

I recently tried to deploy my laravel Nova project in docker, and my search brought me to laravel sail.

So having the default docker-compose.yml file included in the project, I ran the ‘sail up’ command in my project working directory

./vendor/bin/sail up

This command downloaded and setup the images specified in the docker-compose.yml file

version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.1
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.1/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
            - meilisearch
            - selenium
    mysql:
        image: 'mysql/mysql-server:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: "%"
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        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
    meilisearch:
        image: 'getmeili/meilisearch:latest'
        platform: linux/x86_64
        ports:
            - '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
        volumes:
            - 'sailmeilisearch:/data.ms'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "wget", "--no-verbose", "--spider",  "http://localhost:7700/health"]
            retries: 3
            timeout: 5s
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - '${FORWARD_MAILHOG_PORT:-1025}:1025'
            - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
        networks:
            - sail
    selenium:
        image: 'selenium/standalone-chrome'
        volumes:
            - '/dev/shm:/dev/shm'
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:

Then created and launched docker containers from the images

Creating network "my-project_sail" with driver "bridge"
Creating my-project_meilisearch_1 ... done
Creating my-project_redis_1       ... done
Creating my-project_selenium_1    ... done
Creating my-project_mailhog_1     ... done
Creating my-project_mysql_1       ... done
Creating my-project_laravel.test_1 ... done

All the containers were executed successfully except for the my-project_laravel.test_1 container which looped continuously displaying the following error

laravel.test_1  | 2022-01-01 09:54:41,943 INFO success: php entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
laravel.test_1  | 
laravel.test_1  | In ClassLoader.php line 571:
laravel.test_1  |
laravel.test_1  |   include(/var/www/html/vendor/composer/../laravel/nova/src/NovaCoreServicePr
laravel.test_1  |   ovider.php): Failed to open stream: No such file or directory
laravel.test_1  |
laravel.test_1  |
laravel.test_1  | 2022-01-01 09:54:45,682 INFO exited: php (exit status 1; not expected)
laravel.test_1  | 2022-01-01 09:54:46,691 INFO spawned: 'php' with pid 26
laravel.test_1  | 2022-01-01 09:54:47,693 INFO success: php entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
laravel.test_1  | 
laravel.test_1  | In ClassLoader.php line 571:
laravel.test_1  |
laravel.test_1  |   include(/var/www/html/vendor/composer/../laravel/nova/src/NovaCoreServicePr
laravel.test_1  |   ovider.php): Failed to open stream: No such file or directory
laravel.test_1  |
laravel.test_1  |
laravel.test_1  | 2022-01-01 09:54:51,307 INFO exited: php (exit status 1; not expected)
laravel.test_1  | 2022-01-01 09:54:52,322 INFO spawned: 'php' with pid 33

What I’ve tried so far

I executed the below command to actually display the content of the ‘/var/www/html/vendor/laravel’ directory within the container

$ docker exec my-project_laravel.test_1 ls /var/www/html/vendor/laravel/
framework
nova
sail
sanctum
serializable-closure
tinker
ui

But listing the contents of the nova directory displayed above yields "No such file or directory"

$ docker exec my-project_laravel.test_1 ls /var/www/html/vendor/laravel/nova/
ls: cannot access '/var/www/html/vendor/laravel/nova/': No such file or directory

After inspecting the vendor/laravel directory in the project on the host machine (Windows 11), I discovered the nova directory’s icon indicates that it’s a shortcut but when I open its properties, I don’t see the shortcut tab. And the folder has content

This is the content of the vendor/laravel directory

Any help from this point would be great

2

Answers


  1. I suspect you ran composer install from your host computer (Windows 11), however to make it work properly you want to do this from within docker, as it will create a symlink linux style (with the command ln).

    So you might want to remove your vendor folder first that was created by composer. After this you can enter your container by running docker-compose exec laravel.test bash and you will be in your container as if you ssh’d into it.

    Some background as why this command does this: laravel.test is your container name given it the docker-compose definition. Bash is a shell which is available in the current linux distro used by the Dockerfile.

    Login or Signup to reply.
  2. I ran into the same problem and in the docs I found this command:

    docker run --rm 
        -u "$(id -u):$(id -g)" 
        -v $(pwd):/var/www/html 
        -w /var/www/html 
        laravelsail/php81-composer:latest 
        composer install --ignore-platform-reqs
    

    Replace the php version number with yours than run this command in wsl.

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