dyln's avatar
Level 1

Trouble with Sail Devcontainer after setup

I'm having an issue replicating my devcontainer after initial setup.

I'm learning how to use devcontainers with VS Code. I've set up a Laravel application using the devcontainer instructions detailed in the Laravel installation docs, "choosing your sail services" section. This works when I set it up - everything works smoothly. However, committing it to GitHub and installing it elsewhere (as devcontainers are designed to do) leaves me stuck.

I think the right way to install a devcontainer for VSCode is to use the "Clone repository into container volume" menu option given by the Dev Containers extension. This works fine for other devcontainers I've set up using other lanugages like Node. However, trying to set up this Sail devcontainer errors - it can't find the Sail Dockerfile referenced in the docker-compose.yml file, because composer install hasn't been run, so there's no vendor folder. This isn't an issue in initial setup because a temporary Docker container is spun up based on the laravelsail/php82-composer image to set up the Laravel application + sail.

I understand that I could instead clone the repository locally, composer install and then open the dev container like that, but surely that negates the usefulness of devcontainers - I'll have to install php + extensions + composer which takes forever when they're in the Sail image already?

Am I misunderstanding how devcontainers work, is there some "pre-install" step I'm missing, or is the Sail devcontainer just not designed to work like other devcontainers?

Thanks in advance

0 likes
5 replies
dyln's avatar
Level 1

Looks like sail needs to be published to get devcontainer to properly work

martinbean's avatar

@dyln Are you able to run your Laravel project in a DevContainer now?

I‘ve liked the idea of using DevContainers, but think I had the same issue you had initially. But if all it takes is to publish the Sail files, I may give it another shot.

1 like
dyln's avatar
Level 1

@martinbean Pretty much - the last hurdle was that because an .env file isn't created, the WWWGROUP/WWWUSER values referenced in the docker-compose file weren't set. I replaced the references to environment variables with '1000' and it seems to work. The postCreateCommand in the devcontainer.json file fails still with 'operation not permitted' but it still seems to build. I haven't tested it yet but I think all you'll need to do from there is set up your .env file and generate an app key! Let me know how it goes for you.

dyln's avatar
Level 1

@martinbean Unfortunately this doesn't seem to be detected when grabbing the docker-compose.yml. I'm still seeing this in the logs:

Start: Run: docker compose -f /workspaces/[...]/docker-compose.yml --profile * config
Stop (57 ms): Run: docker compose -f /workspaces/[...]/docker-compose.yml --profile * config
name: [...]
services:
  laravel.test:
    build:
      context: /workspaces/[...]/docker/8.2
      dockerfile: Dockerfile
      args:
        WWWGROUP: ""
    depends_on:
      mysql:
        condition: service_started
    environment:
      IGNITION_LOCAL_SITES_PATH: ""
      LARAVEL_SAIL: "1"
      WWWUSER: ""

And:

WARN[0000] The "WWWGROUP" variable is not set. Defaulting to a blank string. 
WARN[0000] The "WWWUSER" variable is not set. Defaulting to a blank string. 

I've tried with containerEnv, remoteEnv, and build.args. The format recommended in the link, ${localEnv:VARIABLE_NAME}, does not work (invalid interpolation format for services.laravel.test.build.args.WWWGROUP. You may need to escape any $ with another $.) I think the next best option is to provide a default for the environment variable:

args:
    WWWGROUP: '${WWWGROUP:-1000}'

The next issue I'm having is Docker mounting artisan as a directory instead of a file 🙃 but if I can't find a fix for this, I will create a new thread. Thanks again for your help.

(sorry for the delayed response)

Please or to participate in this conversation.