How to solve the permission problem encountered by Docker when creating a php development environment

不言
Release: 2023-03-31 09:58:02
Original
3076 people have browsed it

This article mainly introduces solutions to permission problems encountered by Docker when creating a PHP development environment. It has certain reference value and you can learn more if necessary.

Recently, I have run the company's development and testing environments on docker. Because development and testing basically install the code and pull it to this address, and then install the directory and mount it to the mirror directory, such as: I use docker-compose

# development.yml
version: '2'
services:
 php-fpm:
  image: jackluo/php-fpm:5.6.3
  restart: always
  volumes:
   - ./www:/var/www/html
   - ./data:/usr/local/var/log
  extra_hosts:
   - "cache.redis.com:192.168.9.111"
   - "192.168.9.111:192.168.9.111"  
 web:
  image: index.alauda.cn/library/nginx
  restart: always
  links:
   - php-fpm
  volumes:
   - ./config:/etc/nginx/conf.d
   - ./data:/var/log/nginx
  volumes_from:
   - php-fpm
  ports:
   - 80:80
  expose:
   - 80
Copy after login

#jackluo/php-fpm:5.6.3 This is my own Some things have been added to the official image pulled. Specifically, there is docker-library on github.

The current company's PHP framework uses thinkphp. Thinkphp will generate cache files and directories, and the official PHP image will run. The user is www-data. The previous solution was as long as the two users are consistent. So, I created a www-data user locally, such as
, all of which are www-data. Permissions, let’s take a look at the permissions generated by the host on Runtime.
are all 33. What user is 33? ? ? ? , I looked at the permissions in docker
and found that the permissions mounted were 1000, and the one generated by php became www-data

Then I visited the webpage
The webpage shows that there is no write permission. What does this mean?

Actually, this problem has troubled me for a long time. My general solution is to directly grant 777 permissions on Runtime. However, if it is a newly generated php page, I have to execute the permissions given to 777 every time. , I really feel unhappy, I finally found the solution at http://stackoverflow.com/. The official solution is

FROM php:5.6-fpm
RUN usermod -u 1000 www-data
Copy after login

If you are a mac

RUN usermod -u 1000 www-data && usermod -G staff www-data
Copy after login

In this way, the permissions generated by the cache generated by php will be consistent

The problem is solved like this

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

The above is the detailed content of How to solve the permission problem encountered by Docker when creating a php development environment. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!