Reputation: 1039
Please help me!!!
I can't figure out the logic of that.I have a dockerfile file as follows.
FROM php:fpm
RUN touch /var/www/html/foo.php
this is my compose file:
version: '3'
services:
web:
container_name: phpx
build : .
ports:
- "80:80"
volumes:
- ./code:/var/www/html
I never see foo.php in my directory named code. How can I see foo.php?
what is the logic of it? When I remove the 'volumes' parameter, it creates in the container, but my code directory does not see.Because it is not synchronous.
How do I write a code in the dockerfile file?
Upvotes: 1
Views: 3056
Reputation: 1039
I've tried what you said but still can not get a result.I still can't see the foo.php file in the code folder on the host.I didn't find out where I was doing wrong.
Upvotes: 0
Reputation: 21758
To create a directory you can use either
FROM php:fpm
RUN mkdir -p /var/www/html/
RUN touch /var/www/html/foo.php
or
FROM php:fpm
WORKDIR /var/www/html/
RUN touch /var/www/html/foo.php
Now lets build the image like
docker build -t phpx .
Now running like this
docker run -it phpx /bin/sh
Now you can find the /var/www/html/foo.php
file the location.
If you try to mount the empty directory which is code
in our case, it will delete everything in the mounted
directory.
docker run -it -v full_host_path/code:/var/www/html phpx /bin/sh
The possible solution for your problem could be to put foo.php
inside code
and mount the code
dir.
Upvotes: 1
Reputation: 1037
Here is something you might want to look at. In your Dockerfile you need to provide permission for the user to access the location in the container. This was why the file was not being created.
FROM php:fpm
RUN chown $user --recursive /var/www/html && touch /var/www/html/foo.php
I made these changes and i was able to get the file on my host.
Upvotes: 0