sail: Unable to use Sail with GitHub Codespaces

  • Sail Version: 1.19.0
  • Laravel Version: 9.50.2
  • PHP Version: 8.2
  • Host operating system: Linux of some sort

Description:

My repo: https://github.com/garrettw/laravel-skeleton

Not sure if this is the right place to report this bug, but I found someone else that had this error yesterday and they said changing their Dockerfile container config fixed the problem – so I thought I’d start here and see if anyone knew what part of this setup might be incompatible with Codespaces.

I am trying to create a new codespace based on the devcontainer file that Laravel Sail generated – I haven’t modified the docker-compose file. When I create the codespace, the build fails. Below is the creation log.

I have a hunch as to what might be going on… maybe Codespaces doesn’t support multi-container compose files and just wants to throw everything in a single container. Haven’t tested this theory yet. Don’t think that’s it… found evidence around the web of people being able to run multi-container setups. Also I’m seeing something about a docker-in-docker setup… is that the only way to get this working?

=================================================================================
2023-02-15 00:30:46.246Z: Configuration starting...
2023-02-15 00:30:46.252Z: Cloning...

=================================================================================
2023-02-15 00:30:46.274Z: Creating container...
2023-02-15 00:30:46.276Z: $ devcontainer up --id-label Type=codespaces --workspace-folder /var/lib/docker/codespacemount/workspace/laravel-skeleton --mount type=bind,source=/.codespaces/agent/mount/cache,target=/vscode --user-data-folder /var/lib/docker/codespacemount/.persistedshare --container-data-folder .vscode-remote/data/Machine --container-system-data-folder /var/vscode-remote --log-level trace --log-format json --update-remote-user-uid-default never --mount-workspace-git-root false --skip-non-blocking-commands --skip-post-create --remove-existing-container --config "/var/lib/docker/codespacemount/workspace/laravel-skeleton/.devcontainer/devcontainer.json" --override-config /root/.codespaces/shared/merged_devcontainer.json --default-user-env-probe loginInteractiveShell --container-session-data-folder /workspaces/.codespaces/.persistedshare/devcontainers-cli/cache
2023-02-15 00:30:46.505Z: @devcontainers/cli 0.28.0. Node.js v14.21.2. linux 5.4.0-1103-azure x64.
2023-02-15 00:30:47.668Z: Error: Command failed: docker-compose -f /var/lib/docker/codespacemount/workspace/laravel-skeleton/docker-compose.yml -f /var/lib/docker/codespacemount/.persistedshare/docker-compose.codespaces.yml config
2023-02-15 00:30:47.670Z:     at vc (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:1906:867)
2023-02-15 00:30:47.671Z:     at processTicksAndRejections (internal/process/task_queues.js:95:5)
2023-02-15 00:30:47.673Z:     at async rie (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:1872:1370)
2023-02-15 00:30:47.674Z:     at async tie (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:1854:2396)
2023-02-15 00:30:47.678Z: {"outcome":"error","message":"Command failed: docker-compose -f /var/lib/docker/codespacemount/workspace/laravel-skeleton/docker-compose.yml -f /var/lib/docker/codespacemount/.persistedshare/docker-compose.codespaces.yml config","description":"An error occurred retrieving the Docker Compose configuration."}
2023-02-15 00:30:47.680Z:     at async Fie (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:1921:2266)
2023-02-15 00:30:47.689Z:     at async $f (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:1921:3239)
2023-02-15 00:30:47.695Z:     at async eoe (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:2045:17247)
2023-02-15 00:30:47.699Z:     at async Qse (/usr/lib/node_modules/@microsoft/vscode-dev-containers-cli/dist/spec-node/devContainersSpecCLI.js:2045:16993)
2023-02-15 00:30:47.702Z: devcontainer process exited with exit code 1

====================================== ERROR ====================================
2023-02-15 00:30:47.704Z: Failed to create container.
=================================================================================
2023-02-15 00:30:47.707Z: Error: Command failed: docker-compose -f /var/lib/docker/codespacemount/workspace/laravel-skeleton/docker-compose.yml -f /var/lib/docker/codespacemount/.persistedshare/docker-compose.codespaces.yml config
2023-02-15 00:30:47.710Z: Error Code: 1302

====================================== ERROR ====================================
2023-02-15 00:30:47.713Z: Container creation failed.
=================================================================================
2023-02-15 00:30:47.715Z: 

===================================== WARNING ===================================
2023-02-15 00:30:47.718Z: Creating recovery container.
=================================================================================

=================================================================================
2023-02-15 00:30:48.127Z: Creating container...
2023-02-15 00:30:48.130Z: $ devcontainer up --id-label Type=codespaces --workspace-folder /var/lib/docker/codespacemount/workspace/laravel-skeleton --mount type=bind,source=/.codespaces/agent/mount/cache,target=/vscode --user-data-folder /var/lib/docker/codespacemount/.persistedshare --container-data-folder .vscode-remote/data/Machine --container-system-data-folder /var/vscode-remote --log-level trace --log-format json --update-remote-user-uid-default never --mount-workspace-git-root false --skip-non-blocking-commands --skip-post-create --config "/var/lib/docker/codespacemount/workspace/laravel-skeleton/.devcontainer/devcontainer.json" --override-config /root/.codespaces/shared/merged_devcontainer.json --default-user-env-probe loginInteractiveShell --container-session-data-folder /workspaces/.codespaces/.persistedshare/devcontainers-cli/cache
2023-02-15 00:30:48.340Z: @devcontainers/cli 0.28.0. Node.js v14.21.2. linux 5.4.0-1103-azure x64.
2023-02-15 00:31:03.747Z: $alpine -c echo Container started
2023-02-15 00:31:04.057Z: Container started
2023-02-15 00:31:04.386Z: Outcome: success User: vscode WorkspaceFolder: /workspaces/laravel-skeleton
2023-02-15 00:31:04.393Z: devcontainer process exited with exit code 0

=================================================================================
2023-02-15 00:31:05.800Z: Running blocking commands...
2023-02-15 00:31:05.802Z: $ devcontainer up --id-label Type=codespaces --workspace-folder /var/lib/docker/codespacemount/workspace/laravel-skeleton --mount type=bind,source=/.codespaces/agent/mount/cache,target=/vscode --user-data-folder /var/lib/docker/codespacemount/.persistedshare --container-data-folder .vscode-remote/data/Machine --container-system-data-folder /var/vscode-remote --log-level trace --log-format json --update-remote-user-uid-default never --mount-workspace-git-root false --skip-non-blocking-commands --expect-existing-container --config "/var/lib/docker/codespacemount/workspace/laravel-skeleton/.devcontainer/devcontainer.json" --override-config /root/.codespaces/shared/merged_devcontainer.json --default-user-env-probe loginInteractiveShell --container-session-data-folder /workspaces/.codespaces/.persistedshare/devcontainers-cli/cache
2023-02-15 00:31:06.013Z: @devcontainers/cli 0.28.0. Node.js v14.21.2. linux 5.4.0-1103-azure x64.
2023-02-15 00:31:06.270Z: Outcome: success User: vscode WorkspaceFolder: /workspaces/laravel-skeleton
2023-02-15 00:31:06.342Z: devcontainer process exited with exit code 0

=================================================================================
2023-02-15 00:31:06.427Z: Configuring codespace...

=================================================================================
2023-02-15 00:31:06.457Z: Finished configuring codespace.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Ok, so a few issues:

  • When the environment starts, it’s like starting empty, with the source code of the repo. So, vendor directory is not there. What I did here was to publish sail assets locally: php artisan sail:publish
  • This is not enough, because Sail is expected to be brought up by the executable ./vendor/bin/sail. Inside, in its magic, it will figure out what user_id and group_id to use. What I did here was to default in the docker-compose.yml to 1000:1000, since Codespaces is running docker compose up not by ./vendor/bin/sail up and its magic. image

The thing got working. Kind of. Because then it also needs the other usual steps, like .env file, composer install, key:generate, storage:link, etc

image

I’ve recently contributed an example on Gitpod which is solves the same problem as Codespaces, and I have set it up here: https://github.com/gitpod-samples/template-php-laravel-mysql/blob/main/.gitpod.yml

There is a multitude of things to do to put it to work, and I don’t know Codespaces enough to do the other steps right now.

But be assured, there is nothing wrong with the current Sail repo. Wether it has a template ready for Codespaces, it’s a separate discussion.

The link I provided should be of guidance. Have a nice one!

I’ve followed this instructions and added the Laravel magic in .devcontainer/devcontainer.json :

 "postCreateCommand": "chown -R 1000:1000 /var/www/html && cp .env.example .env && composer install && php artisan key:generate && php artisan storage:link --force && php artisan migrate --force --seed && npm install",
 "postStartCommand": "npm run dev",

It works !

I think the first mayor problem is that the docker-compose.yml is referencing a file that is in the vendor folder that doesnt exist yet

context: ./vendor/laravel/sail/runtimes/8.2

@Daniel-Mendes awesome! One question though – do you have it working with the standard docker-compose.yml that comes with the repo?

I had to change vendor/ call to the published version in the repo and changed '${WWWGROUP:-1000}'

docker-compose.yml

version: "3"
services:
    laravel.test:
        build:
            context: ./docker/8.2
            dockerfile: Dockerfile
            args:
                WWWGROUP: "${WWWGROUP:-1000}"
        image: sail-8.2/app
        extra_hosts:
            - "host.docker.internal:host-gateway"
        ports:
            - "${APP_PORT:-80}:80"
            - "${VITE_PORT:-5173}:${VITE_PORT:-5173}"
        environment:
            WWWUSER: "${WWWUSER:-1000}"
            LARAVEL_SAIL: 1
            IGNITION_LOCAL_SITES_PATH: "${PWD}"
        volumes:
            - ".:/var/www/html"
        networks:
            - sail
        depends_on:
            - mysql
            - phpmyadmin
            - redis
            - mailpit
            - minio
            - soketi
    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:
            - "sail-mysql:/var/lib/mysql"
            - "./docker/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/create-testing-database.sh"
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - mysqladmin
                - ping
                - "-p${DB_PASSWORD}"
            retries: 3
            timeout: 5s
    phpmyadmin:
        image: "phpmyadmin:latest"
        ports:
            - 8080:80
        networks:
            - sail
        environment:
            PMA_ARBITRARY: 1
    redis:
        image: "redis:alpine"
        ports:
            - "${FORWARD_REDIS_PORT:-6379}:6379"
        volumes:
            - "sail-redis:/data"
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - redis-cli
                - ping
            retries: 3
            timeout: 5s
    mailpit:
        image: "axllent/mailpit:latest"
        ports:
            - "${FORWARD_MAILPIT_PORT:-1025}:1025"
            - "${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025"
        networks:
            - sail
    minio:
        image: "minio/minio:latest"
        ports:
            - "${FORWARD_MINIO_PORT:-9000}:9000"
            - "${FORWARD_MINIO_CONSOLE_PORT:-8900}:8900"
        environment:
            MINIO_ROOT_USER: sail
            MINIO_ROOT_PASSWORD: password
        volumes:
            - "sail-minio:/data/minio"
        networks:
            - sail
        command: 'minio server /data/minio --console-address ":8900"'
        healthcheck:
            test:
                - CMD
                - curl
                - "-f"
                - "http://localhost:9000/minio/health/live"
            retries: 3
            timeout: 5s
    soketi:
        image: "quay.io/soketi/soketi:latest-16-alpine"
        environment:
            SOKETI_DEBUG: "${SOKETI_DEBUG:-1}"
            SOKETI_METRICS_SERVER_PORT: "9601"
            SOKETI_DEFAULT_APP_ID: "${PUSHER_APP_ID}"
            SOKETI_DEFAULT_APP_KEY: "${PUSHER_APP_KEY}"
            SOKETI_DEFAULT_APP_SECRET: "${PUSHER_APP_SECRET}"
        ports:
            - "${PUSHER_PORT:-6001}:6001"
            - "${PUSHER_METRICS_PORT:-9601}:9601"
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local
    sail-redis:
        driver: local
    sail-minio:
        driver: local

.devcontainer/devcontainer.json

// https://aka.ms/devcontainer.json
{
    "name": "Laravel Sail",
    "dockerComposeFile": [
        "../docker-compose.yml"
    ],
    "service": "laravel.test",
    "workspaceFolder": "/var/www/html",
    "customizations": {
        "vscode": {
            "extensions": [
                "onecentlin.laravel-extension-pack",
                "Vue.volar",
                "nhedger.inertia",
                "dbaeumer.vscode-eslint",
                "esbenp.prettier-vscode",
            ],
            "settings": {
                "editor.formatOnSave": true,
                "editor.codeActionsOnSave": {
                    "source.fixAll.eslint": true
                },
                "files.autoSave": "onFocusChange",
                "[vue]": {
                    "editor.defaultFormatter": "esbenp.prettier-vscode"
                },
                "[javascript]": {
                    "editor.defaultFormatter": "esbenp.prettier-vscode"
                }
            }
        }
    },
    "remoteUser": "sail",
    "postCreateCommand": "chown -R 1000:1000 /var/www/html && cp .env.example .env && composer install && php artisan key:generate && php artisan storage:link --force && php artisan migrate --force --seed && npm install",
    "postStartCommand": "npm run dev",
    "forwardPorts": [
        80,
        8025,
        8080,
        6001,
        5173,
        8900
    ],
    "portsAttributes": {
        "80": {
            "label": "Application",
            "onAutoForward": "notify"
        },
        "8025": {
            "label": "Mailpit"
        },
        "8080": {
            "label": "phpMyAdmin"
        },
        "5173": {
            "label": "Vite (hmr)"
        },
        "6001": {
            "label": "Soketi"
        },
        "8900": {
            "label": "Minio"
        }
    }
}

In this case the issue is not only codespaces not working. Because the devcontainer is not self-containing. The issue is the same as mentioned in docs if you want to you sail in a project that already exists you need to install sail via composer first if you freshly cloned the project.

That’s the same issue that codespaces has.

So the devcontainer should be changed do be self-containing & not rely on any “vendor” stuff that cannot exist if you clone your repository.

First fix could be to publish the runtime images on hub and reference them as image in docker-compose.yaml instead of building from vendor.

or running php artisan sail:publish

Anyway… the devcontainer.json setup is not “newcomer” friendly