Reputation: 8938
I'm using a docker image as my dev
environment for a specific version of PHP. I am using PHP for a command line script so every time I make a change to the script I would like it to automatically make changes in the container.
I'm not sure if this is even possible. I assumed it was. I mostly use docker-compose
and I can add VOLUMES
easily to achieve this, but not in this instance with docker.
My Dockerfile:
FROM php:7.2-cli
COPY ./app /usr/src/app/
WORKDIR /usr/src/app
ENTRYPOINT [ "php" ]
CMD [ "./index.php" ]
I first run:
docker build -t app .
And then
docker run app
Everything works well. But if I change something in index.php
I have to run the steps again. Is this expected behaviour or is there any way to have docker watch for changes?
Upvotes: 6
Views: 6134
Reputation: 21559
If you are editing a file using vim/sublime outside docker in your host, this is normal, because vim/sublime does not simple "edit" that file, but create a new file. see : https://github.com/moby/moby/issues/15793
solution:
After some googling, Sublime text has atomic_save instead so Adding "atomic_save": false to user preferences worked (After a restart).
if you are using docker-compose, use this command:
$ docker-compose run --build
Upvotes: 1
Reputation: 3667
docker run -v /home/user/location:/usr/src/app app
Use a volume so that the files within the container reflect local changes.
https://docs.docker.com/storage/volumes/#choose-the--v-or---mount-flag
Upvotes: 2