How to apply changes to my code automatically in my container without restarting it

Good morning,
Currently I have an app that I run in a Docker container. when I launch the container my app works and therefore I would like to work via this container, that is to say continue to develop my app by necessarily changing the code.
I work with phpStorm, but I notice that when I modify files in my app, they are not taken into account when I reload the page because in fact the container is frozen on an image of the build.
I wanted to know if there is a way to persist the data. That is to say that the changes made to my code apply automatically, so my container is automatically updated without restarting a build of an image ?

Good morning!

Simply link the volume to the local file path as in this video:

In the video the docke-compose.yml looks like this:

Volumes:
   - ./:/var/www/html

The ./ means that the files in the current directory of your host are used on the container in /var/www/html/

You can also use an absolute path such as /var/local/home/projects/my-stuff/
If you are on Windows, you can use /C/user/name/projects/my-stuff/

I hope this helps.

does work …

i build with this command :
docker build . -t ulysse-sondage -f ./docker/Dockerfile

then i create a volume :
docker volume create ulysse-sondage

and then i use this commande to exec container with the volume :
docker run -tid --name ulysse-sondage -p 8080:80 --mount source=ulysse-sondage,target=/var/www/public ulysse-sondage:latest

i set the volume indocker-compose.yml with :
./:/var/www/public
public because my project use symfony

After this, i try to modify a simple texte in my twwig html, but when i refresh the page, modification does not appear

There are two different ways.

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. But they do not use the data form your local directory directly.

And the other way are bind mounts.
When you use a bind mount, a file or directory on the host machine is mounted into a container directly.

You sould use bind mounts as in this example:

docker run -d \
  -it \
  --name devtest \
  --mount type=bind,source="$(pwd)"/target,target=/app \
  nginx:latest

It is not necessary to create a separate named volume if you use bind mounts.

Please note that it could also be the cache of Symfony.

And if you have a Docker Compose file, than you can use “docker compose up --build” to build and run the container. Take a look under:

Or use the Docker Built-In Functions in PHPStorm as shown in the video. But you have to enable the Docker plugin.