by Devin Yang
(This article was automatically translated.)

Published - 3 years ago ( Updated - 3 years ago )

This is the full record of manually changing the fpm owner on my Nas.

1. First download the latest image I want to use. In this article, 7.4.13 is the new version of php I want to use.
​​​​​​​docker pull deviny/fpm:7.4.13
The actual screen is as follows:


2. Enter the D-Laravel directory, and modify the php service of docker-compose.yml to use the latest php (deviny/fpm:7.4.13) version.
cd /volume1/docker/dlaravel
vi docker-compose.yml

Operation screen (I use vi editor):


3. In the yaml file, modify the paragraph of the container service php, and adjust it to the fpm version just downloaded.
### PHP-FPM container ##################################
php:
image: deviny/fpm:7.4.13
volumes:
The actual screen is as follows:



4. Leave after archiving and restart the container. At this time, run the new version of php.
You can use docker-compose to remove and restart, or the bash provided by D-Laravel.
./console restart
#We can also use the docker-compose command to restart, the result is equivalent to the above command, and the meaning is the same:
#docker-compose down --remove-orphans
#docker-compose up -d
After the restart is complete, we execute the command to check. You will see that the user running the container is 1000, which is the default user uid of D-Laravel.
Why do I need to replace it, because I execute it with the admin account on the NAS, which will cause php to have no permission to write to the container folder, so I need to replace it with the same uid (1024) as admin.
admin@CCC:/volume1/docker/dlaravel$ docker-compose exec php id
uid=1000(dlaravel) gid=1000(dlaravel) groups=1000(dlaravel)

5. How to query what your own uid is, just execute id.
admin@CCC:/volume1/docker/dlaravel$ id
uid=1024(admin) gid=100(users) groups=100(users),0(root),101(administrators)
Actual operation screen:

Or, if I want to change the uid of other users, I can also use the id command to query.
admin@CCC:/volume1$ id -u devin
1027
As shown above, devin's uid is 1027.

6. Adjust permissions of etc/php-fpm.d/www.conf
user = 1024
group = 100
The content of my file is as follows:


7. Before starting to adjust the container uid, we can confirm again that the container php service is started.
./console ps
#Alternatively, docker-compose can also be used to check whether the php/fpm permission is enabled.
docker-compose ps php
Actual operation execution screen:


You can also use the docker-compose command to view, port 9000 is the service of php fpm, and the status is Up, which means the container is running.
doesn't work how do we change the permissions inside the container right? :)


Eighth, the main event is here, because the container is Up, so we can execute the instructions in the container on the host side, and issue instructions to adjust the permissions of the user uid, gid and home directory in the container. The instructions are as follows:
#容器中使用者的uid
docker-compose exec -uroot php usermod -u 1024 dlaravel
#The gid of the user in the container
docker-compose exec -uroot php usermod -g 100 dlaravel
# directory permissions in the container
docker-compose exec -uroot php chown -R 1024 /home/dlaravel
In the above command, 1024 is the uid of my admin, you should adjust it according to the uid you want to change.

9. After completing the adjustment, remember to save (commint) the container we changed, we can get the running container id through the following command.
docker ps|grep php
# or docker-compose command
docker-compose exec php hostname
To obtain the container id, you can use the ./console command provided by D-Laravel, or you can use dockr-compose, and the execution results are the same.
In the actual execution screen below, I deliberately use ./console and docker-compose to execute each once.


10. Continuing from the previous step, my container id is 47fcd589fc2b, here I set a new name admin/fpm:7.4.13.
After executing the following command, a new image can be created, and the content is the image we have adjusted uid and gid.
docker commit 47fcd589fc2b admin/fpm:7.4.13


11. After finishing, remember to modify our own docker-compose.yml to use the modified image.


12. After changing the image of the new version, restart and verify whether the uid in the container has changed.
#重啟
./console restart
# enter the container
./console
# check container user id
id

Thirteen, take a look, the dlaravel uid in the container has been changed from 1000 to the 1024 we specified :).


Remarks, the /tmp directory in your container will save the old PHP session. You need to log in to the container as root, empty it and commit the container again.
These old sessions have uid 1000, which will cause the new admin permission to be 1024 and cannot write changes, so the old sessions need to be cleared, if there are users who have logged in to the website during the adjustment process.

1. Log in to the php container as root
admin@CCC:/volume1/docker/dlaravel$ docker-compose exec -uroot php bash
root@0d7682041752:/var/www/html#
2. Clear all files with uid 1000 under /tmp, because here my new uid is 1024, not the default 1000.
find /tmp -uid 1000 -name sess* -exec rm -f {} \;

#Or don't want any session to be committed, cleared without distinction, all users will be logged out, anyway, I want to restart the container :).
rm -rf /tmp/sess*

3. After performing the adjustment, remember to commit the changed version again.


We can pass a file to the public directory and test it. The actual operation screen:


Open the webpage to see, it is 1024 instead of the original 100.


 

Tags: docker container laravel

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


docker,php,cli

MacOS's php is not powerful, use docker to execute laravel installer

It's very simple, just add an "alias" alias laravel='docker run --rm -v ${PWD}:/var/www/html -v ~/.dlaravel/cache:/home/dlaravel/.composer /cache -ti deviny/fpm:8.1.10 /home/dlaravel/.composer/vendor/bin/laravel'

dlaravel

Use D-Laravel to build your own dedicated php fpm image.

D-Laravel has provided a built php image, if you need to adjust it yourself and build your own dedicated image is quite simple. 1. First, enter dockerfiles/fpm in D-Laravel, and select the PHP version you want to build, such as 7.2. The command is as follows...

dlaravel

Safe Update D-Laravel

How to upgrade the current D-Laravel. If your current use environment is very smooth and you have not encountered any problems, you don't need to update it. If you want to use the latest version, and bug fixes, etc., please read this article carefully, In order to ensure a smooth upgrade, the following is the recommended way to upgrade D-Laravel.