0

After I exit the shell everything that I do inside a container is lost. Is it possible to make it save its state beyond the environment defined by its image?

Simple test: write FROM ubuntu inside a Dockerfile then create the image with:

docker build -t test .

Get the image with: docker image ls, then create and run the container:

docker run -d -ti imageid /bin/bash

Once inside, touch /opt/test.txt then exit the shell. What magic would make it possible to see the test file again once a container finished, without touching its image? Or is it exactly the point of containers to never save their state past their image?

Note that I want to avoid mounting local directories, my question is not about how to save data processed by a container, but about saving the filesystem of a container once it finished, beyond its actual image. What if you want to use a development container in order to build its image properly for example? You start working on the container, install some software, do tests, then you have to close it for some time and then "boot" back into it to continue working...

grokkaine
  • 789
  • 2
  • 7
  • 20
  • 2
    To "boot" back you can use `docker start `. Check if this is helpful: [I lose my data when the container exits](https://stackoverflow.com/questions/19585028/i-lose-my-data-when-the-container-exits). It is very common for new docker users to keep using `docker run ...` and this way keep spinning up new containers... – tgogos May 16 '18 at 08:05
  • ahhh nailed it. I tried that last time but maybe I made an error, and it made me re-evaluate my core beliefs. Thanks for the tip, I should probably delete my question, it was too stupid. – grokkaine May 16 '18 at 08:29
  • I'm glad I've helped :-) – tgogos May 16 '18 at 08:36

1 Answers1

1

Thanks to @tgogos comment, I got the container ID with docker ps -a, then:

$ docker start containerid
$ docker attach containerid

More info here: I lose my data when the container exits

grokkaine
  • 789
  • 2
  • 7
  • 20