I am new to docker and flask web framework, my docker context has a flask file, a mod_wsgi file, and the python script. As I am new to flask, there are a lot of small changes which I keep doing. For any change to the docker context to take into effect I have to:

  1. Kill the container and prune it out of the system.
  2. Make changes to the Dockerfile and then rebuild the container.
  3. In some cases I have to even remove the image and rebuild it as the changes are not taken into effect if cache is retained.

Is there any way in which I can have the changes into the docker context taken into effect during run time. I tried to have the docker context shared as a volume as that is the preferred way to persist data in Docker containers and services, but that did not work, any changes still were not reflected.

Could you please let me know of any way I can achieve this. Any suggestion would be greatly appreciated.

Thanks and regards, Shailesh

1 Answer 1


Mounted volumes can be used to preserve state between runs, apart from that Docker is stateless by design. To make a local directory available inside the Docker container, you can use the -v option, for example:

docker run -v /path/to/local/dir/:/mountpath/inside/docker ...

But if I understand your question correctly, you are asking for a faster feedback cycle while working on the Dockerfile. For that, I would recommend to start the container, and attach an interactive shell to try out your changes. Once you made some progress, update the Dockerfile.

$ docker ps
f1217635695d  ubuntu:18.04 "bash"   23 seconds ago   Up 21 seconds         stoic_austin

$ docker exec -it f1217635695d bash
root@f1217635695d:/# ...

Also note that proper use of caching can speed up rebuilds of the Docker container after changes significantly.

(from your question) 1. Kill the container and prune it out of the system.

Pruning should not be necessary unless you run out of disk space. It should be sufficient to update the tag, for example:

docker build -t test .
docker run --rm -it test

test:latest will point to the last image id that was created. docker images will show that the previous images are not deleted, but as said, if you have enough disk space available, it is not a big concern.

  • Thank you for your reply. As I understand it, my only option is to exec into the container, make changes and then update the Dockerfile. I execed into the container with root permissions and made changes to my Dockerfile, then committed those changes: docker commit <container-id> myimage:0.1, but when I checked it on my docker context the changes were not taken into effect. Is my understanding correct, how else can I get a faster feedback cycle when working on Dockerfile. May 3, 2019 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.