1

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

Kristi Jorgji
  • 1,154
  • 1
  • 14
  • 39
  • Docker doesn't manage the ownership of either host-directory or named-volume content. If `$KJ_WORDPRESS_PATH` is a host directory, you might be able to `sudo chown` that host directory to the right (numeric) uid; I'd also expect your `docker-compose exec ... chown` command to "stick" in this case. – David Maze Jul 08 '22 at 16:49
  • @DavidMaze that is what I am doing now as also mentioned in the post. I just wanted to automate this in some other way. Currently I added in my entrypoint script that part to manually chown as first thing – Kristi Jorgji Jul 11 '22 at 09:55

1 Answers1

1

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:
EnterSB
  • 984
  • 2
  • 10
  • 27
  • i think im looking for something similar here. i want to chown my workspace to the user before i switch that user in the docker file. (basically anything that root installed, change to 'myuser' ownsership, then switch to 'myuser'. – mike01010 Mar 25 '23 at 19:01