Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

longestdrive's avatar

Laravel Sail Up - invalid Group Id & Permissions on created files

HI On an ubuntu 22 machine I've been having problems with file permissions created from within the docker container - e.g a migration file. This has meant I needed to sudo chown each file that's been created to make my user on the local machine to be able to access and amend the file etc. This has worked for a while but now trying to install node_modules I'm getting permission errors all over the installs.

So, a bit of dangerous googling and I decided to uninstall docker-desktop and install just docker cli - which is proving a bit of a problem.

I now have docker running but trying sail up I now get the error:

------
 sail:ravel.test  6/11] RUN groupadd --force -g 1000
'.305 groupadd: invalid group ID '1000
------
failed to solve: process "/bin/sh -c groupadd --force -g $WWWGROUP sail" did not complete successfully: exit code: 3

In my env file I have:

WWWGROUP=1000
WWWUSER=1000

and my docker-compose file has:

# For more information: https://laravel.com/docs/sail
version: '3'
services:
  laravel.test:
    build:
      context: ./vendor/laravel/sail/runtimes/8.2
      dockerfile: Dockerfile
      args:
        WWWGROUP: '${WWWGROUP}'
    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}'
      LARAVEL_SAIL: 1
      XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-debug}'
      XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
    volumes:
      - '.:/var/www/html'
    networks:
      - sail
    depends_on:
      - mysql
      - phpmyadmin
  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'
      - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-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
networks:
  sail:
    driver: bridge
volumes:
  sail-mysql:
    driver: local

For now I've removed the entries from my env file and I can get sail up to work but still have permission errors

How can I add the right user and group to the start and is there anything else I can do, to get permissions to work effectively?

Thanks you

0 likes
3 replies
LaryAI's avatar
Level 58

The issue you're encountering with file permissions and group IDs in Laravel Sail on an Ubuntu 22 machine is a common one when dealing with Docker containers. Here’s a step-by-step solution to address the problem:

Step 1: Verify User and Group IDs

First, ensure that the user and group IDs you are using in your .env file are correct and do not conflict with existing IDs on your host system.

You can check your current user and group IDs with the following commands:

id -u
id -g

These commands will output your user ID (UID) and group ID (GID). Make sure these IDs match the WWWUSER and WWWGROUP values in your .env file.

Step 2: Update Dockerfile

If the IDs are correct, you might need to adjust the Dockerfile used by Laravel Sail to ensure it correctly sets the user and group. You can customize the Dockerfile by copying it from the Sail package to your project directory and modifying it.

  1. Copy the Dockerfile from the Sail package:
cp vendor/laravel/sail/runtimes/8.2/Dockerfile Dockerfile
  1. Open the copied Dockerfile and modify the groupadd and useradd commands to ensure they use the correct IDs:
# Dockerfile

# Add the group and user with the specified IDs
RUN groupadd --force -g ${WWWGROUP} sail \
    && useradd -ms /bin/bash --no-user-group -g ${WWWGROUP} -u ${WWWUSER} sail

Step 3: Update docker-compose.yml

Ensure your docker-compose.yml file correctly passes the environment variables to the build context:

# docker-compose.yml

version: '3'
services:
  laravel.test:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        WWWGROUP: '${WWWGROUP}'
        WWWUSER: '${WWWUSER}'
    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}'
      LARAVEL_SAIL: 1
      XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-debug}'
      XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
    volumes:
      - '.:/var/www/html'
    networks:
      - sail
    depends_on:
      - mysql
      - phpmyadmin
  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'
      - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-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
networks:
  sail:
    driver: bridge
volumes:
  sail-mysql:
    driver: local

Step 4: Rebuild and Start Sail

After making these changes, rebuild your Docker images and start Sail:

./vendor/bin/sail build --no-cache
./vendor/bin/sail up

Step 5: Fix Existing File Permissions

To fix the permissions of existing files, you can run the following commands on your host machine:

sudo chown -R $USER:$USER .

This command will recursively change the ownership of all files in your project directory to your current user and group.

Conclusion

By ensuring the correct user and group IDs are used and properly configuring the Dockerfile and docker-compose.yml, you should be able to resolve the permission issues you're experiencing with Laravel Sail on your Ubuntu 22 machine.

longestdrive's avatar

Sadly that didn't work. I've also reinstalled docker cli and deleted any containers but it still fails with invalid group id.

longestdrive's avatar

I managed to get this to work by replacing the environment variables oid WWWGROUP and WWWUSER with 1000, effectively hardcoding so possibly something to do with the env file and comments?

Please or to participate in this conversation.