简体   繁体   中英

How can I create a shared volume with non-root access rights and docker-compose?

Before I decided that it is probably a good idea to run the web service not as root in its Docker container, I simply had

version: '3'
services:
  web:
    build: .
    ...
    volumes:
     - .:/opt/app  # enables hot code reloading
     - uploads:/opt/app/uploads         
  ...
volumes:
    uploads:
        driver: local

in order to have the folder /opt/app/uploads within the client being identical to the uploads folder on the host.

Now, having added a new non-root user, I see the problem that the volume directory /opt/app/uploads gets assigned to the root, not to the user.

How can I fix that?

(I know that I can access the container and do it manually ... but I would like to know if there is a simpler solution; eg editing the Dockerfile or the docker-compose.yml )

Was rather simple: Add the following line to the Dockerfile . Make sure the directory has the rights you want.

RUN mkdir -p /opt/app/uploads

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM