Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run the app container as a non-root user #264

Merged
merged 1 commit into from
May 3, 2024
Merged

Conversation

ucan-lab
Copy link
Owner

@ucan-lab ucan-lab commented May 3, 2024

Problem

When a file system is bind mounted in a container, the uid and gid are used as they are between the host machine and the container, causing a problem where the owner of the file written by the container becomes the root user.

See #258

One possibility is to run Docker itself in rootless mode, but it also seems possible to assign non-root users the same UID and GID as Linux.

Run the container as phper:phper, which is the opposite of the root user.

Operation confirmation

$ task for-linux-env # Linux environment only
$ task create-project

# or...

$ make for-linux-env # Linux environment only
$ make create-project

# or...

$ echo "UID=$(id -u)" >> .env # Linux environment only
$ echo "GID=$(id -g)" >> .env # Linux environment only

$ mkdir -p src
$ docker compose build
$ docker compose up -d
$ docker compose exec app composer create-project --prefer-dist laravel/laravel .
$ docker compose exec app php artisan key:generate
$ docker compose exec app php artisan storage:link
$ docker compose exec app chmod -R 777 storage bootstrap/cache
$ docker compose exec app php artisan migrate

http://localhost

  • Docker for Mac
  • Docker for Windows
  • Linux

Help

I'm currently not in a position to try it on Linux, so I'd like someone to review it.

@ucan-lab ucan-lab added enhancement New feature or request help wanted Extra attention is needed labels May 3, 2024
@ucan-lab ucan-lab self-assigned this May 3, 2024
@ucan-lab ucan-lab changed the title feat: Run the app container as a non-root user Run the app container as a non-root user May 3, 2024
@ucan-lab ucan-lab added the minor Minor version up label May 3, 2024
@ucan-lab
Copy link
Owner Author

ucan-lab commented May 3, 2024

The Linux and Windows environments are not ready, but since CI is running, I will try merging them.

@ucan-lab ucan-lab merged commit 569cf0d into main May 3, 2024
3 checks passed
@ucan-lab ucan-lab deleted the feat-258-non-root-user branch May 3, 2024 15:47
This was referenced Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed minor Minor version up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant