Touch command does not work docker-compose volume

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'

container_name: phpx
build : .
- "80:80"
 - ./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?

There must be hundreds of examples on the web for using docker in development context. Either the one you follow is wrong so find a better one, or follow it more closley.

Here’s the first thing: mounting a volume hides the content built into the image. Foo.php inside the image is hidden by mounting ./code on top of foo.php’s directory.

Second thing, in development context, the files you intend to edit should be on the host filesystem, not inside the image. Otherwise, the changes would be gone when the container is removed. (Or, the changes would be more difficult to get to, even if you could save them in docker storage before the container is removed.)

So, remove the touch command from the dockerfile and rebuild the image. It’s obfuscating.
Then touch or add content to ./code/foo.php.
Then start the container again.

Hack the files in the ./code directory.