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


openspeedtest,docker,phpenv

Run OpenSpeedTest with phpenv

Although we may use websites such as speedtest to test the speed of uploading and uploading, what if we want to test the speed of our own Server? For example, if the user is in another country, the speed of connecting to our host is slow, then the self-hosted test tool is very convenient. The latest version of phpenv has added openspeedtest.yml to the yml file of services.

docker,laravel

[D-Laravel]./console node

When developing Laravel, sometimes we need to install nodejs packages through npm, but Node in our system is not new enough. It may be impossible to upgrade due to some factors, such as running an old version of nodejs program, etc. In fact, we can use docker through simple commands, so that we can use the latest version of node image to mount the /sites folder on the host side. In this way, we can execute the new version of the npm command at any time.

laravel,Laravel security

Lock IP in Laravel debug mode

Laravel's debugging mode is quite rich. Laravel's official website has a reminder that you can set APP_DEBUG to true for local development, but in the production environment, this value must always be False.