php - WordPress running within Docker instance, unable to write to file
Get the solution ↓↓↓I am completely new to docker. Just trying to run WordPress within a docker instance to learn more about it.
./public_html/ - has WordPress files and from the domain, I am able to access the installer. However the WordPress installer cant update wp-config.php within docker - as below error.
Unable to write to wp-config.php file.
version: '3'
services:
web:
image: webdevops/php-apache:7.2
container_name: web
restart: always
environment:
- PHP_DISPLAY_ERRORS=1
- PHP_MEMORY_LIMIT=2048M
- PHP_MAX_EXECUTION_TIME=300
- PHP_POST_MAX_SIZE=500M
- PHP_UPLOAD_MAX_FILESIZE=256M
volumes:
- ./public_html/:/app
ports:
- "80:80"
- "443:443"
links:
- mysql
mysql:
image: mariadb:10
container_name: mysql
restart: always
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
volumes:
- db-data:/var/lib/mysql
phpmyadmin:
container_name: phpmyadmin
restart: always
image: phpmyadmin/phpmyadmin:latest
# environment:
# - MYSQL_ROOT_PASSWORD=root
# - PMA_USER=root
# - PMA_PASSWORD=root
ports:
- "8080:80"
links:
- mysql:db
depends_on:
- mysql
volumes:
db-data:
external: false
Now WordPress allow me to create the config.php. installation went on. I just tried to upload a plugin to test and I get below error. which I anticipated.
Unable to create directory wp-content/uploads/2021/02. Is its parent directory writable by the server?
I logged into the docker "docker exec -it 51af15ed3678 bash" to check file permission.
root@51af15ed3678:/# ls -lart
total 104
drwxr-xr-x 2 root root 4096 Nov 22 12:37 boot
drwxr-xr-x 2 root root 4096 Dec 9 23:22 srv
drwxr-xr-x 2 root root 4096 Dec 9 23:22 mnt
drwxr-xr-x 2 root root 4096 Dec 9 23:22 media
drwxr-xr-x 2 root root 4096 Dec 9 23:22 lib64
drwx------ 2 root root 4096 Feb 27 22:12 entrypoint.d
lrwxrwxrwx 1 root root 28 Feb 27 22:12 entrypoint.cmd -> /opt/docker/bin/entrypoint.d
lrwxrwxrwx 1 root root 29 Feb 27 22:12 entrypoint -> /opt/docker/bin/entrypoint.sh
drwxr-xr-x 1 root root 4096 Feb 27 22:12 home
drwx------ 1 root root 4096 Feb 27 22:31 root
drwxr-xr-x 1 root root 4096 Feb 27 22:36 sbin
drwxr-xr-x 1 root root 4096 Feb 27 22:36 lib
drwxr-xr-x 1 root root 4096 Feb 27 22:36 bin
drwxr-xr-x 1 root root 4096 Feb 27 22:36 var
drwxr-xr-x 1 root root 4096 Feb 27 22:36 usr
drwxr-xr-x 1 root root 4096 Feb 27 22:36 opt
drwxr-xr-x 1 root root 4096 Feb 28 13:36 etc
-rwxr-xr-x 1 root root 0 Feb 28 13:36 .dockerenv
dr-xr-xr-x 197 root root 0 Feb 28 13:36 proc
dr-xr-xr-x 13 root root 0 Feb 28 13:36 sys
lrwxrwxrwx 1 root root 12 Feb 28 13:36 docker.stdout -> /proc/1/fd/1
lrwxrwxrwx 1 root root 12 Feb 28 13:36 docker.stderr -> /proc/1/fd/2
srwx------ 1 root root 0 Feb 28 13:36 .supervisor.sock
drwxr-xr-x 5 root root 360 Feb 28 13:36 dev
drwxr-xr-x 1 root root 4096 Feb 28 13:36 run
drwxr-xr-x 5 root root 4096 Feb 28 17:24 app
drwxr-xr-x 1 root root 4096 Feb 28 17:28 ..
drwxr-xr-x 1 root root 4096 Feb 28 17:28 .
root@51af15ed3678:/# cd app
root@51af15ed3678:/app# ls -lart
total 32876
-rwxr-xr-x 1 root root 3300 Feb 6 2020 wp-load.php
-rwxr-xr-x 1 root root 2496 Feb 6 2020 wp-links-opml.php
-rwxr-xr-x 1 root root 2913 Feb 6 2020 wp-config-sample.php
-rwxr-xr-x 1 root root 351 Feb 6 2020 wp-blog-header.php
-rwxr-xr-x 1 root root 405 Feb 6 2020 index.php
-rwxr-xr-x 1 root root 19915 Feb 12 2020 license.txt
-rwxr-xr-x 1 root root 8509 Apr 14 2020 wp-mail.php
-rwxr-xr-x 1 root root 3236 Jun 8 2020 xmlrpc.php
-rwxr-xr-x 1 root root 7278 Jun 26 2020 readme.html
-rwxr-xr-x 1 root root 7101 Jul 28 2020 wp-activate.php
-rwxr-xr-x 1 root root 3939 Jul 30 2020 wp-cron.php
-rwxr-xr-x 1 root root 31337 Sep 30 21:54 wp-signup.php
-rwxr-xr-x 1 root root 4747 Oct 8 21:15 wp-trackback.php
-rwxr-xr-x 1 root root 2328 Oct 8 21:15 wp-comments-post.php
-rwxr-xr-x 1 root root 49831 Nov 9 10:53 wp-login.php
-rwxr-xr-x 1 root root 20975 Nov 12 14:43 wp-settings.php
drwxr-xr-x 25 root root 12288 Feb 22 15:10 wp-includes
drwxr-xr-x 4 root root 4096 Feb 22 15:10 wp-content
drwxr-xr-x 9 root root 4096 Feb 22 15:10 wp-admin
-rwxr-xr-x 1 root root 16712083 Feb 22 15:10 latest.zip.1
-rwxr-xr-x 1 root root 16712083 Feb 22 15:10 latest.zip
-rw-r--r-- 1 root root 3181 Feb 28 17:24 wp-config.php
drwxr-xr-x 5 root root 4096 Feb 28 17:24 .
drwxr-xr-x 1 root root 4096 Feb 28 17:28 ..
root@51af15ed3678:/app#
Any clue will be a great help. Thank you.
Regards, Dwija
Answer
Solution:
The image is running the daemon under userapplication
(UID 1000; GID 1000) so make sure all files are owned by the userapplication
notroot
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: php_network_getaddresses: getaddrinfo failed: temporary failure in name resolution
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.