Replies: 3 comments 1 reply
-
|
Thanks for the compliments! I'm very interested in replicating the problem you reported:
Could you add a little more detail? Here's an overview what we like to look for when reproducing issues: https://serversideup.net/ask-for-help/ |
Beta Was this translation helpful? Give feedback.
-
|
Ah crap, I made it too abstract. I was trying to avoid accusations of being self-promoting by linking to my image repo. Also, truth be told, I'm actually embarrassed revealing my low level docker chops.
I've shoehorned this into your issue template and it will get repetitive. 👉 Describe the problemI'm porting a CMS image to use your FrankenPHP image as the new base. I cannot stand up a fresh instance of the CMS with bind mounted persistent directories on the host.
📝 Steps to reproduceHere are steps for four variations of containers you can recreate. The first recreates the problem. The others are variants for comparison: General setupYou might need to set these variables for your environment or preferences: UID/GID, port, a common container name prefix, and possibly host mount targets. To be safe, make sure your host user has permissions to create directories under the parent of the host mounts you specify. You can modify most of these settings by creating this file and placing it as .env# NAME_PREFIX=
# PUID=83
# PGID=83
# PORT=562XHere is the setup process I followed: $ mkdir -p ~/tmp/repro
$ cd ~/tmp/reproCompose filesAll tests bring up containers using docker-compose.yamlservices:
grav:
environment:
LOG_LEVEL: 10Smoke tests
Test 1We will set up and run a container based on SSU's FrankenPHP variant with bind mounts to host directories that do not exist. Copy and create this docker-compose file, saving as test1.yamlname: d562_test1
services:
grav:
build:
context: https://github.com/hughbris/cadaver.git#ssu-franken
args:
php_ver: 8.4
PUID: ${PUID:-1000}
PGID: ${PGID:-1000}
container_name: ${NAME_PREFIX:-d562}-test1
ports:
- "127.0.0.1:${PORT:-5621}:8080"
volumes:
# - ./test1/backup:/var/www/grav/backup # unnecessary for testing and development, uncomment if you like
# - ./test1/logs:/var/www/grav/logs # unnecessary for testing and development, uncomment if you like
- ./test1/user:/var/www/grav/userI recommend starting this one with attached terminal output (no $ docker-compose -f docker-compose.yaml -f test1.yaml up
(Also I'm aware that there is quite a bit of setup in my Dockerfile that there is a probably superior SSU utility for. Replacement is still in progress.) Test 2We will set up and run a container based on SSU's FrankenPHP variant without any mounts to host directories. The container will be completely ephemeral. Copy and create this docker-compose file, saving as test2.yamlname: d562_test2
services:
grav:
build:
context: https://github.com/hughbris/cadaver.git#ssu-franken
args:
php_ver: 8.4
PUID: ${PUID:-1000}
PGID: ${PGID:-1000}
container_name: ${NAME_PREFIX:-d562}-test2
ports:
- "127.0.0.1:${PORT:-5622}:8080"Now fire it up: $ docker-compose -f docker-compose.yaml -f test2.yaml up -dTest 3We will set up and run a container based on a current packaged image, which uses official php-fpm and with main process running nasty privileged. We bind mount to host directories that do not exist. Copy and create this docker-compose file, saving as test3.yamlname: d562_test3
services:
grav:
image: ghcr.io/hughbris/cadaver:dev
build: # alt build option (*)
context: https://github.com/hughbris/cadaver.git#develop
args:
php_ver: 8.4
PUID: ${PUID:-1000}
PGID: ${PGID:-1000}
container_name: ${NAME_PREFIX:-d562}-test3
ports:
- "127.0.0.1:${PORT:-5623}:2015"
volumes:
# - ./test3/backup:/var/www/grav/backup # unnecessary for testing and development, uncomment if you like
# - ./test3/logs:/var/www/grav/logs # unnecessary for testing and development, uncomment if you like
- ./test3/user:/var/www/grav/user(*) If you need a Now fire it up: $ docker-compose -f docker-compose.yaml -f test3.yaml up -dTest 4We will set up and run a container based on SSU's FrankenPHP variant with bind mounts to host directories that do exist. In fact, which we created in the previous test. We'll do this and retain our naming convention by symlinking: $ ln -s test3 test4
Now copy and create this docker-compose file, saving as test4.yamlname: d562_test4
services:
grav:
build:
context: https://github.com/hughbris/cadaver.git#ssu-franken
args:
php_ver: 8.4
PUID: ${PUID:-1000}
PGID: ${PGID:-1000}
container_name: ${NAME_PREFIX:-d562}-test4
ports:
- "127.0.0.1:${PORT:-5624}:8080"
# don't forget to symlink!: `ln -s test3 test4`
volumes:
# - ./test4/backup:/var/www/grav/backup # unnecessary for testing and development, uncomment if you like
# - ./test4/logs:/var/www/grav/logs # unnecessary for testing and development, uncomment if you like
- ./test4/user:/var/www/grav/userNow fire it up: $ docker-compose -f docker-compose.yaml -f test4.yaml up -d🙏 Expected behaviorAll variations will produce containers that return HTTP $ curl -I 127.0.0.1:<port>
HTTP/1.1 200 OK
…🔥 Actual behaviorTest 1 FAILS:
Tests 2-4 PASS:
🌎 EnvironmentDocker on Linux. 📸 Additional contextI don't think so. |
Beta Was this translation helpful? Give feedback.
-
|
I think I had the same problem but figured it out after some reading. Docker volumes and mounts are initialised before the container is started and always by the user "root". COPY --chown=www-data:www-data . /var/www/html Alternatively in your Dockerfile you switch to the "root" user, update the permissions and then set the user back to "www-data". USER root Of course I may have completely misunderstood what you're talking about @hughbris |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Preamble: I post this with some trepidation for a couple of reasons:
I think this has been touched on but not answered in a way that helps my situation.
Context: I have derived a flat file CMS image from the upcoming FrankenPHP variation after a few failed attempts in the past, including with a couple of the other variants on offer. This is awesome, I'm pumped! I'm very keen to migrate my package to this base eventually (hopefully soon).
I'm getting there, I promise.
Problem: With no volumes or mounts of any kind, containers stand up and run pretty nicely it seems. I tend to use bind mounts exclusively because I find named volumes a PITA for development and git deployments. When I bind-mount existing host directories, no problems either. The problems start when I want to specify new bind mount directories and start containers.
(The environment is all Linux, FWIW.)
In simple terms, the containers exit because the required filesystems are created on the host with root permissions, and the directories required by the CMS can not be populated with files by a script on container start. As I've learned, this is Docker's documented behaviour for bind mounts, but not for named volumes – Docker creates any non-existing host directories with root privileges where a bind mount is specified. (I would love to know why the two types of persistent storage are initialised differently — there may be good reasons — but it seems it's just "by design" and we are left to shrug our shoulders.)
So the images work fine for existing install mount points but not when creating new ones.
My current images based off official php-fpm base images do not have this problem because the entrypoint script runs privileged. I do like that serversideup have found a way around that still allows me to change GID/UIDs, but I believe this to be the underlying cause of the problem here.
I've experimented a little with different initial host filesystem setups. The only direction I can offer to users to seed a new installation successfully, using my image, is to first create the bind-mounted directories on the host, then set their permissions to the user ID that the container runs as (83, 1000, whatever), and then bring the container up. When I do that, the mount points do get seeded correctly with the files required to run, and persist a working instance of the CMS. However, I don't think that's really a workable requirement or reasonable directive.
Possible suggestion: What would probably work around this without compromising container security is if I could run some commands (like permission setting) at startup. Would it be feasible to create another folder (like
/entrypoint.d) or a file naming pattern where I can put startup scripts I want to run as root?I hope I've been clear here. I'm open to any other suggested solutions or workarounds that don't affect image users' experience. Also happy to clarify anything because I would love to get this working under the new variant.
If this is reasonable, what process do you suggest I follow to progress it?
Beta Was this translation helpful? Give feedback.
All reactions