Answers: <p>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 <code>-v</code> option, for example:</p>
  
  <p><code>docker run -v /path/to/local/dir/:/mountpath/inside/docker ...</code></p>
  
  <p>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.</p>
  
  <pre><code>$ docker ps
  CONTAINER ID  IMAGE        COMMAND  CREATED           STATUS        PORTS  NAMES
  f1217635695d  ubuntu:18.04 "bash"   23 seconds ago   Up 21 seconds         stoic_austin
  
  $ docker exec -it f1217635695d bash
  root@f1217635695d:/# ...
  </code></pre>
  
  <p>Also note that proper use of caching can speed up rebuilds of the Docker container after changes significantly.</p>
  
  <blockquote>
    <p>(from your question)
    1. Kill the container and prune it out of the system.</p>
  </blockquote>
  
  <p>Pruning should not be necessary unless you run out of disk space. It should be sufficient to update the tag, for example:</p>
  
  <pre><code>docker build -t test .
  docker run --rm -it test
  </code></pre>
  
  <p><code>test:latest</code> will point to the last image id that was created. <code>docker images</code> 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.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-05-03T06:45:23.240Z
Answers: 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.
Answers: Shailesh Bg
Answers: CC BY-SA 4.0
Answers: 2019-04-30T21:48:16.627Z
Answers: 2019-04-30T21:48:16.627Z
Answers: Philipp Claßen
Body: <p>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:</p>
  
  <ol>
  <li>Kill the container and prune it out of the system.</li>
  <li>Make changes to the Dockerfile and then rebuild the container.</li>
  <li>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.</li>
  </ol>
  
  <p>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.</p>
  
  <p>Could you please let me know of any way I can achieve this. Any suggestion would be greatly appreciated.</p>
  
  <p>Thanks and regards,
  Shailesh  </p>
  
Tags: <docker>
Title: Persisting data in docker context
UserDisplayName: Shailesh Bg
ThreadText: # Persisting data in docker context
  
  (Asked by: username_0 on 2019-04-30)
  
  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,
  username_0
  
  **Tags:** docker
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-04-30. Score: 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
  CONTAINER ID  IMAGE        COMMAND  CREATED           STATUS        PORTS  NAMES
  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.
  
  > **Comments:**
  > **username_0**: 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.  
  
  ---
  
  