At the moment I have setup a simple lamp stack environment with docker.
However, when I specify e.g. a php.ini file, the php.ini file shows up as a folder and not a specific ini file - which means that I cannot edit it.
some volumes context of my dockerfile:
volumes:
- ./:/var/www/html
- ./.docker/php/custom.ini:/usr/local/etc/php/php.ini
What am I missing? php.ini should be a file, and not a folder, no?.
Directories are created whenever Docker cannot find the file specified, leading to it assuming you want it created.
Don't use relative directories in volume mounts, always use the full path, for example by prefixing your bind mount with $(pwd).
If you're a Docker Desktop user, make sure you have allowed the given path to be mounted as volume.
Related
I am having a little bit of trouble with write permissions on a named volume with an upload folder for wordpress, i am using one container to run php which has a bind bound to the wordpress files so they can be edited when needed, but a named volume mapped to the uploads folder.
So in docker-compose:
volumes:
- ./Exrugged-Website:/usr/share/nginx/html:rw
- exrugged-uploads:/usr/share/nginx/html/website/wp-content/uploads:rw
So i've given it a bind mount to the actual full set of files so php can see them as the site itself is on another container (please tell me if there is a better way to allow php to see the files) , but the upload folder is on the named volume which is shared with the website container.
All the files on the named volume are owned by user 1000:1000 and i have the php container set to run as that:
user: 1000:1000
In wp admin it won't allow me to upload files, it says the uploads folder isn't writable but when i check the permissions the user and group has full write access. I'm a little confused and i am thinking maybe it's the double mapping that's the issue?
I use Dockerfile to build an image of php, but as the default, PHP don't have a php.ini file. So I need to create it. Now I have three ways to do this:
use RUN command in Dockerfile RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini. But this way still use a default setting, I can't edit it (or edit it and commit container).
use COPY command in Dockerfile COPY php.ini /usr/local/etc/php/php.ini. OK, now I can edit the config and then build image, but if I need to change some setting, I need rebuild image
use volumn args, add this in docker-compose.yml - $PWD/php/conf.d:/usr/local/etc/php/conf.d/my_config. By this way, I can edit php.ini anytime and just reload config file. But, the best way I wonder is - $PWD/php/conf.d:/usr/local/etc/php/conf.d. the first way will create a new sub folder in docker container, the second way will delete the *.ini file that originally in the folder
I want to know is here some way that could mount volumn and don't delete the file in container (the second way of 3 but don't delete file)
Actually the files are not deleted from the subfolder. The volume is mounted over it.
Reference
What you can do is, assign a separate folder for your *.ini files, and reference it from the main php.ini file. So every time you reload php, it goes to php.ini and from there it gets your dedicated config folder and loads all the *.ini files from there.
Code of Dockerfile is here
FROM php:7.0-cli
COPY ./ /
Code of create.php is here
<?php
$fp = fopen($argv[1],'wa+');
fwrite($fp,'sample');
fclose($fp);
?>
I build my docker using following command in debian - stretch
docker build -t create-tool .
I run it using following command in debian - stretch
docker run create-tool php create.php /home/user1/Desktop/test
But it is not creating the file, instead it throws the error "failed to open stream".
3 Scenarios I would investigate :
Because /home/user1/Desktop/test doesn't exist within the docker container. That file exists on your host system, so it's out of reach for the container.
If you want to access files on your host, you'll need to share the folders you want the container to access with a volume.
The path exists in your container, but is for example a directory. You can check quickly if a file exists and/or is accessible within your container by running docker run create-tool ls -lsah /home/user1/Desktop/test.
This will then list what the container can access with the given path.
Double-check what the value of $argv[1] in your PHP script is. You wouldn't want to get escaped characters, etc. print_r($argv); should help.
How about using touch()? It can solve your problem!
http://php.net/manual/en/function.touch.php
I want to connect a nginx and a php-fpm container using a unix socket and have the php-fpm be completely disconnected from any network for security reasons.
I could of course just create the php-fpm.sock file somewhere on my docker host and mount it into both containers, however I would like the socket file to be automatically cleaned when the containers shut down and not have to worry about creating / shipping it with my docker-compse.yml. I therefore thought about creating a named volume in docker-compose and mount it as /var/run/. This is however (I think) not good, because I don't want everything in /var/run/ to be shared, but only php-fpm.sock. Is there a way to create a named single-file volume in docker-compose?
If the directory structure is as:
.
|__docker-compose.yml
|__php-fpm.sock
Then you can use following volume in your compose file:
volumes:
- ./php-fpm.sock:/var/run/php-fpm.sock
Yes, instead of mounting /var/run/ just mount /var/run/php-fpm.sock
I am using Docker-machine on Mac for a PHP application.
My code is shored in mac, and shared to docker-machine as volume.
This is my docker-compose.yml
app:
build: .
volumes:
- .:/var/www/html
My PHP application will create a folder in the shared volume and write some files in it.
The shared volume is set to permission 777 on mac (which I know I shouldn't do it, but I cannot solve the problem even with this)
After running the application, I got mkdir(): Permission denied.
The newly created folder is in permission drwxr-xr-x, so my application cannot write any file in it.
Is there anyway to set the new folders to inherit folder permission from its parent?
You might want to look at http://docker-sync.io - using unison as strategoy, you can actually properly map the uid on the user in the container, removing any issues with permissions.