Docker-compose set user and group on mounted volume

前端 未结 4 496
感情败类
感情败类 2020-12-07 15:36

I\'m trying to mount a volume in docker-compose to apache image. The problem is, that apache in my docker is run under www-data:www-data but the mounted directo

4条回答
  •  轮回少年
    2020-12-07 16:00

    To achieve the desired behavior without changing owner / permissions on the host system do the following steps.

    1. add the definition to your docker-compose.yml

      user: "${UID}:${GID}"
      

      so your file could look like this

      php: # this is my service name
          user: "${UID}:${GID}" # we added this line to get a specific user / group id
          image: php:7.3-fpm-alpine # this is my image
      # and so on
      
    2. set the values in your .env file

      UID=1000
      GID=1001
      

    Now your user in the container has the id 1000 and the group is 1001 and you can set that differently for every environment.

    If you don't use docker-compose or want to know more different approaches to achieve this have a read through my source of information: https://dev.to/acro5piano/specifying-user-and-group-in-docker-i2e

提交回复
热议问题