简体   繁体   中英

How to mount a volume with docker-compose with owner www-data user of the container?

I have my docker-compose like below

  "kj_wordpress":
    image: kristijorgji/wordpress-php-7.1:0.0.0
    volumes:
      - ${KJ_WORDPRESS_PATH}:/var/www/html/app
    restart: on-failure
    container_name: "kj_wordpress"

This is working fine and I can access one wordpress site. The problem is that the user of nginx (www-data) cannot access write permissions on wp-contents/uploads and fails to upload images there.

I can fix that manually by entering inside the running container like

docker-compose exec kj_wordpress /bin/bash

then run

chown -R www-data wp-content/uploads/

That works great.

Now I want to automate the process and not have to run that every time the container is created and run.

How can I make www-data user ot - ${KJ_WORDPRESS_PATH}:/var/www/html/app

so the container path /var/www/html/app

I had similar if not same question 2 years ago. There were few options, I tested marked answer until some point.

Docker-compose and named volume permission denied

This is how I did it with docker compose later.

    files-init:
        image: alpine
        restart: "no"
        entrypoint: |
            /bin/sh -c "chown myuser:myuser /path/to/folder"
        volumes:
            - logs:/path/to/folder
    service-logs:
        image: alpine
        depends_on:
            - files-init
    volumes:
        logs:

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