


How to solve the permission problem encountered by Docker when creating a php development environment
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
#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
If you are a mac
RUN usermod -u 1000 www-data && usermod -G staff www-data
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

The steps to update a Docker image are as follows: Pull the latest image tag New image Delete the old image for a specific tag (optional) Restart the container (if needed)

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

To get the Docker version, you can perform the following steps: Run the Docker command "docker --version" to view the client and server versions. For Mac or Windows, you can also view version information through the Version tab of the Docker Desktop GUI or the About Docker Desktop menu.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

To save the image in Docker, you can use the docker commit command to create a new image, containing the current state of the specified container, syntax: docker commit [Options] Container ID Image name. To save the image to the repository, you can use the docker push command, syntax: docker push image name [: tag]. To import saved images, you can use the docker pull command, syntax: docker pull image name [: tag].

Methods for copying files to external hosts in Docker: Use the docker cp command: Execute docker cp [Options] <Container Path> <Host Path>. Using data volumes: Create a directory on the host, and use the -v parameter to mount the directory into the container when creating the container to achieve bidirectional file synchronization.

You can switch to the domestic mirror source. The steps are as follows: 1. Edit the configuration file /etc/docker/daemon.json and add the mirror source address; 2. After saving and exiting, restart the Docker service sudo systemctl restart docker to improve the image download speed and stability.
