Docker creating files inside container with my host user as owner

Viewed 40

I wonder how can i create files inside docker with my host user privileges to it.

This is my docker-compose:

version: "3"

networks:
  main_network:

services:
  php_8_fpm:
    build:
      context: php8.0-fpm
    volumes:
      - ../src:/var/www/
    networks:
      - main_network


  web_server_nginx:
    build:
      context: webserver
    volumes:
      - ../src:/var/www/
      - ./webserver/conf.d:/etc/nginx/conf.d
    networks:
      - main_network
    ports:
      - "8100:80"
    depends_on:
      - php_8_fpm

I'm using composer inside the php container. Problem is when i create any file inside the container i dont have privileges from my host. On my host these files have root as owner. Is there any good practice to prevent this insead of chaning owner on my host every time i create a new file inside container? Even when i use bin/console make:entity i dont have privilege to it.

1 Answers

There is a config that you can use into docker-compose, there is multiple way to do it read this, it will help you

Related