ampache / ampache-docker

Ampache docker package
http://ampache.org
93 stars 68 forks source link

ampache.cfg.php.dist is not readable when we mount a volume for ampache config #12

Open arielelkin opened 7 years ago

arielelkin commented 7 years ago

I want to persist the Ampache configuration files so that I don't have to reinstall and reconfigure Ampache if docker or the ampache container stop for some reason.

Here's what I do:

$ docker \
  run --name=ampache \
  -v /mymusic:/media:ro  \
  -v /ampache_config:/var/www/config \
  -p 2008:80 -d ampache/ampache

Ampache seems to install fine, and then in the Requirements check of the installation wizard, I get this:

image

But the container does have access to that directory:

$ docker inspect ampache

...
 "HostConfig": {
            "Binds": [
                "/ampache_config:/var/www/config:rw",
                "/mymusic:/media:ro"
            ],
...

Any thoughts?

arielelkin commented 7 years ago

Update:

We need to add the following line to run.sh to let PHP write to the config directory:

chown www-data:www-data -R /var/www/config

The install wizard will then tell us that ampache.cfg.php is writable!

But at the step where it generates the config file, it’s giving me this error:

Error: Config files not found or unreadable

Basically it can’t find the template ampache.cfg.php… But the dockerfile doesn’t actually install it?

Am I missing something?

tonyisworking commented 7 years ago

I followed your tip above

chown www-data:www-data -R /var/www/config

Then I got the ampache.cfg.php.dist in the repo and manually put it in the config folder. Then the buttons were then set to OK and was able to proceed.

You can check the run.sh file to see that it moved it over. mv /var/temp/ampache.cfg.php.dist /var/www/config/ampache.cfg.php.dist

Then everything seems to install okay.

bigforcegun commented 4 years ago

I't bad idea modify files on host machine from docker.

Instead you need use right UID and GID from host machine in image for www-data user.

bigforcegun commented 4 years ago

Here good example of GID and UID setup for docker-containers - https://docs.linuxserver.io

It sad, but another way to map user rights from host machine to docker volumes are full of pain

--user docker options working bad with volumes

lachlan-00 commented 4 years ago

you shouldn't need to do anything special. If you build with your config file it gets copied over from the dockerfile and then copied on run.

Dockerfile

COPY ampache.cfg.* /var/temp/

run.sh

if [[ -f /var/temp/ampache.cfg.php && ! -f /var/www/config/ampache.cfg.php ]]; then
    mv /var/temp/ampache.cfg.php /var/www/config/ampache.cfg.php
fi
bigforcegun commented 4 years ago

If you build with your config file it gets copied over from the dockerfile and then copied on run.

This issue is not about custom build of image, it's about launching a image with mounted volume for configs. Even if i build custom docker container with my dist config - the issue still here - i will get not readable config

you shouldn't need to do anything special.

In most host machines docker www-data GID UID not match with HOST machine GID UID - so when image start and copy config we have bad file permissions :man_shrugging:

So i need do many special things to run this image properly.


For now i use special entrypoint for docker-compose

#!/usr/bin/env bash
usermod -a -G users www-data #I't work only for my host machine, you need use groups from yours
exec /run.sh

then my config.php becomes readable

lachlan-00 commented 4 years ago

I'll test out what you've said and see what I can do.

lachlan-00 commented 4 years ago

This worked fine. test.php comes up all readable.

docker run --name=ampache -d -v /mnt/files-music/albums/:/media:ro -v /var/www/config/:/var/www/config/:rw -p 8888:80 ampache/ampache
bigforcegun commented 4 years ago

Can you check in this example /mnt/files-music/albums/ default file permissions?

/mnt/files-music/albums/ - very similar to SMB mount with default 777 permissions


My point has not changed - on host machine we have user www-data with different UID then internal docker or host machine have no user www-data.

You can emulate this with usermod -u 3333 www-data or just try to mount volume with no www-data owner - then config been nor readable.

lachlan-00 commented 4 years ago

That seems like something that's not an issue with the host not the image.

Superpiffer commented 4 years ago

Can you check in this example /mnt/files-music/albums/ default file permissions?

/mnt/files-music/albums/ - very similar to SMB mount with default 777 permissions

My point has not changed - on host machine we have user www-data with different UID then internal docker or host machine have no user www-data.

You can emulate this with usermod -u 3333 www-data or just try to mount volume with no www-data owner - then config been nor readable.

I second that, the approach in this container works if the music folder is used only by ampache or if all other containers use the same UID and GID, but for configurations with many concurrent services (like mine) maybe is not ideal. Using the USER docker directive it's not useful too because the container use root for the database.

kuzi-moto commented 2 years ago

I believe I fixed this. Should be able to specify UID and GID environment values in the docker-compose.yml file. Will set Ampache's internal www-data user to the ID you specify.

xeruf commented 2 years ago

@kuzi-moto can you show how to concretely do this?

kuzi-moto commented 2 years ago

I will try to remember to do it tomorrow!

raaron773 commented 2 years ago

I tried adding PGID and PUID in environment section in the docker-compose file. It's the same thing right ? @kuzi-moto because if it is then it didn't work if not then how do I go about this?

EDIT: This is what I did: https://pastebin.com/RKTxP7JN

xeruf commented 2 years ago

The warning stays, even though the option seems to work...

lead0r commented 1 year ago

I tried adding PGID and PUID in environment section in the docker-compose file. It's the same thing right ? @kuzi-moto because if it is then it didn't work if not then how do I go about this?

EDIT: This is what I did: https://pastebin.com/RKTxP7JN

There is a typo in your file: "enivironment"

KaeTuuN commented 1 year ago

@kuzi-moto That works great!

@raaron773 It's PID and UID not PGID and PUID!

@lachlan-00 I think this can be closed.

TanqBQZ commented 10 months ago

@KaeTuuN It's GID and UID

KaeTuuN commented 10 months ago

@KaeTuuN It's GID and UID

That's what I wrote!?