I'm trying to change the user: root to www-data in Dockerfile to build wordpress image. Once I run the dockerfile and go inside the image: the permission is not changed.
This is my Dockerfile:
FROM wordpress:php7.1-apache
COPY . /var/www/html
WORKDIR /var/www/html
RUN chown -R www-data:www-data /var/www/html/
RUN chmod -R 777 /var/www/html
This is the result in the image by running that Dockerfie:
root#081507c3824e:/var/www/html# ls -lh
total 228K
-rw-r--r-- 1 root root 149 Jul 5 05:09 Dockerfile
-rw-r--r-- 1 root root 405 Jul 5 05:09 index.php
-rw-r--r-- 1 root root 20K Jul 5 05:09 license.txt
-rw-r--r-- 1 root root 7.2K Jul 5 05:09 readme.html
drwxr-xr-x 9 root root 4.0K Jul 5 05:15 wp-admin
-rw-r--r-- 1 root root 351 Jul 5 05:09 wp-blog-header.php
/var/www/html is marked a VOLUME in Dockerfile of wordpress. Your RUN instruction won't persist after the build.
You can try any of the following approaches if you want to change the permisions of /var/www/html/ directory.
You can mount a directory with modified permissions from host machine into the container.
You can create an entrypoint script which changes the permission of the directory before starting the main process.
Related
I've started to play with R, and wanted to build a simple custom image. When attempting to launch a new container with the r-base official image, using the instructions provided, it fails.
$ docker run -ti --rm r-base
ERROR: R_HOME ('/usr/lib/R') not found
I'm running Debian 10, on WSL2:
$ uname -r
5.4.72-microsoft-standard-WSL2
$ lsb_release -a
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster
$ docker --version
Docker version 18.09.1, build 4c52b90
Launching a container with bash, there are files in the mentioned lib directory:
$ docker run -ti --rm r-base /bin/bash
root#f27f0139a6be:/# ls -l /usr/lib/R/
total 28
drwxr-xr-x 3 root root 4096 Jul 12 13:23 bin
lrwxrwxrwx 1 root root 33 Jun 23 10:26 COPYING -> ../../share/common-licenses/GPL-2
drwxr-xr-x 2 root root 4096 Jul 12 13:23 etc
drwxr-xr-x 2 root root 4096 Jul 12 13:23 lib
drwxr-xr-x 32 root root 4096 Jul 12 13:23 library
drwxr-xr-x 2 root root 4096 Jul 12 13:23 modules
drwxr-xr-x 4 root root 4096 Jul 12 13:23 site-library
-rw-r--r-- 1 root root 46 Jun 23 10:26 SVN-REVISION
root#f27f0139a6be:/# R
ERROR: R_HOME ('/usr/lib/R') not found
I've played around with a few different recent tags/versions of the image, but same issue. Is this some incompatibility with WSL2? Am I missing an environment variable?
I am planning to use Wordpress official docker image on Amazon ECS. The problem is that instead working on the root path https://www.example.com/, I need it to work on a subdirectory path https://www.example.com/blog/.
To modify this I am planning to create a new Docker image based on the official Wordpress docker image.
My current Dockerfile looks like this.
FROM wordpress:6.0.1-apache
# Copying to premium so user can access it through
# domain/blog
RUN cd /var/www/html; \
mkdir blog; \
cp !\(blog\) blog; \
# We copy the wordpress instance to subdirectory and disable
# access to the root instance.
echo "Hello World!" > /var/www/html/index.php;
However this doesn't work. When I access https://www.example.com/blog it shows Forbidden.
The log shows this
[autoindex:error] [pid 23] [client 172.30.0.1:61822] AH01276: Cannot serve directory /var/www/html/blog/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
It seems that the image does not copy the wordpress library.
wordpress % docker compose exec wordpress bash
root#63d417de7f31:/var/www/html# ls
index.php blog wp-config.php wp-content
root#63d417de7f31:/var/www/html# ls -al
total 32
drwxrwxrwx 4 www-data www-data 4096 Aug 5 06:13 .
drwxr-xr-x 1 root root 4096 Aug 2 07:49 ..
-rw-r--r-- 1 root root 13 Aug 5 06:06 index.php
drwxr-xr-x 2 root root 4096 Aug 5 06:06 blog
-rw-r--r-- 1 www-data www-data 5584 Aug 5 06:13 wp-config.php
drwxrwxrwx 5 www-data www-data 4096 Aug 5 06:13 wp-content
root#63d417de7f31:/var/www/html# ls -al blog/
total 8
drwxr-xr-x 2 root root 4096 Aug 5 06:06 .
drwxrwxrwx 4 www-data www-data 4096 Aug 5 06:13 ..
root#63d417de7f31:/var/www/html# exit
What should I do?
Update 1
When I trim the Dockerfile to just the base image like this,
FROM wordpress:6.0.1-apache
the wordpress files are copied into /var/www/html.
% docker compose exec wordpress bash
root#f9ad22323268:/var/www/html# ls
index.php wp-admin wp-config-sample.php wp-includes wp-mail.php xmlrpc.php
license.txt wp-blog-header.php wp-config.php wp-links-opml.php wp-settings.php
readme.html wp-comments-post.php wp-content wp-load.php wp-signup.php
wp-activate.php wp-config-docker.php wp-cron.php wp-login.php wp-trackback.php
Update 2
I tried using this
FROM wordpress:6.0.1-apache
WORKDIR /var/www/html/blog
This copies the Wordpress installation both in /var/www/html and /var/www/html/blog. This still fits the requirement, however I want to remove the one in /var/www/html/. I tried rewriting to /var/www/html/index.php like below
FROM wordpress:6.0.1-apache
WORKDIR /var/www/html/blog
RUN echo "Hello World!" > /var/www/html/index.php
But it's not rewritten. Seems like it's being rewritten from the entrypoint
https://github.com/docker-library/wordpress/blob/master/docker-entrypoint.sh
Give Apache user access to blog directory. By adding following to Dockerfile
RUN chown -R www-data:www-data /var/www/html/blog
Running php on my Ubuntu box
The PHP process runs under my current user account named tiger
Below are the file permissions for the wp-content folder
drwxr-xr-x 15 tiger www-data 4.0K Apr 23 10:16 wp-content
When the Wordpress blog editor tries to upload photos through the Wordpress dashboard, they are presented with below error
Below is the file hierarchy for WordPress showing file permissions.
root-site-directory/ drwxr-xr-x 15 tiger www-data
`-- wp-content drwxr-xr-x 15 tiger www-data
`-- uploads drwxr-xr-x 15 tiger www-data
`-- 2022 drwxr-xr-x 15 tiger www-data
`-- 04 drwxr-xr-x 15 tiger www-data
What am I missing ?
I am working on Solaris 10 machine. In that i cannot able to untar my file. Logs are given below. Anyone please suggest what may be the issue? I can able to create tar file but unable to untar. :(
bash-3.2# ls -lrth ConfigCheck-120614-KL.out*
-rw-r--r-- 1 root root 144K Jun 12 17:15 ConfigCheck-120614-KL.out
-rwxrwxrwx 1 root root 146K Jun 16 16:49 ConfigCheck-120614-KL.out.tar
bash-3.2# tar xvf ConfigCheck-120614-KL.out.tar
tar: extract not authorized
bash-3.2# tar tvf ConfigCheck-120614-KL.out.tar
-rw-r--r-- 0/0 147377 Jun 12 17:15 2014 ConfigCheck-120614-KL.out
Solaris 11 tar will fail with that error message if you are running as uid 0 but do not have the Media Restore profile set up in the RBAC configuration.
Unless you're trying to restore from backup, you should normally be untarring files as a normal user, not root, to avoid accidentally overwriting critical system files.
I keep seeing a 403 error for my stylesheet which is hosted on my Rasberry Pi (webserver). I ran ls -al and this is the result:
pi#raspberrypi ~/www $ ls -al
total 16
drwxr-xr-x 2 pi root 4096 Mar 17 20:18 .
drwxr-xr-x 12 root root 4096 Mar 15 16:44 ..
-rw-r--r-- 1 pi root 644 Mar 17 20:18 index.html
-rw------- 1 pi root 329 Mar 17 20:19 stylesheet.css
The index.html data shows up when I point my browser at the ip, but there is no formatting and whenever I try to acess the css file through looking at the source code it keeps telling me theres a 403 error :(
Can anyone help a brother out??
Cheers!
You need proper permissions for the www folder, and that depends on which webserver you are running. For apache on debian the user is www-data, if your webroot is ~/www and you are user pi try these commands
Change owner to apache user recursively
Change Permissions to read for all recursively
chown -R www-data:www-data /home/pi/www
chmod -R 644 /home/pi/www