17

I'm fairly new to Docker and has stumbled on a problem that I have been unable to figure out any solutions to.

I'm on a Mac so I have to use Boot2Docker as my environment. I do all my stuff inside the VM using boot2docker ssh to mimic a "real" situation as far as possible.

My problem is that as soon as I close down boot2docker with boot2docker down or stop I loose all my changes... How can I persist my edits?

What I have done is to create some directories, /opt/sites for instance, and added some code to .profile. All is gone when I start boot2docker up again.

I have tried to put everything at /Users... as boot2docker 1.3 and upwards auto mounts that location but then I get problem using --volumes on some containers (more specifically MySQL containers...)

I think I can solve the data storage, (--volumes problem), but where do I put the definition of PATH and other environment variables?

I'm probably misunderstanding something so please point me in the right direction ;-)

Thomas Rambrant
  • 171
  • 1
  • 5
  • 1
    A question (I may be way off here). You do create docker containers as well right? That is where you mount the volumes and that is where you setup your MySQL etc. The Boot2Docker is simply a small Linux VM that is used since Mac OSX is not Linux. – wassgren Jan 14 '15 at 08:08
  • I do create containers and I do mount the volumes. But when I map a volume for my MYSQL container to store its database on, (/Users...) it fails... If I mount a volume on /opt/sites/mysql/data it all works. Im trying to create an environment where I use bash scripts to setup, create, run, start and stop groups of containers. I would like to set my PATH variable to point these scripts out. I have the scripts on /Users... so they are safe but how do I set my PATH variable inside the VM in a persistent way? – Thomas Rambrant Jan 14 '15 at 08:27
  • Ok, and can you show me what you do to mount it? – wassgren Jan 14 '15 at 08:31
  • Thanks for trying to help me, I appreciate it much docker run \ --name=redmine-mysql \ -d \ --env-file $SITE_ROOT/redmine/mysql.env \ -v $SITE_ROOT/redmine/mysql:/var/lib/mysql \ sameersbn/mysql When SITE_ROOT points to a directory on /Users I get problems with MySQL... If I point it to /opt/sites in the boot2docker environment (boot2docker ssh) then it works. Thats one side of the problem the other one is that everything in the boot2docker environment is gone if I stop and start... Shouldn't things be persistent in the VM? Can't you start and stop it without loosing everything in it? – Thomas Rambrant Jan 14 '15 at 11:43
  • Trying to learn formatting but was interupted... `docker run \ --name=redmine-mysql \ -d \ --env-file $SITE_ROOT/redmine/mysql.env \ -v $SITE_ROOT/redmine/mysql:/var/lib/mysql \ sameersbn/mysql` A bit easier to read... – Thomas Rambrant Jan 14 '15 at 11:55

3 Answers3

9

After you make your changes to the boot2docker image, run the 'boot2docker save' command. You should see your changes persist after you restart boot2docker.

andy.jackson
  • 111
  • 1
  • 7
  • 2
    Unfortunately, there is no `docker-machine save`. See [my answer](http://stackoverflow.com/questions/27938193/how-to-persist-changes-in-boot2docker/37028510#37028510) for a solution. – pavelst May 04 '16 at 14:01
5

If you are using Docker Toolbox, you use docker-machine instead of boot2docker. There is unfortunately no equivalent to boot2docker save for docker-machine, as stated in Migrate from Boot2Docker to Docker Machine.

Instead, you should use /var/lib/boot2docker/profile file inside your boot2docker VM to persist the initial script that runs every time the boot2docker VM restarts. See more in this github issue.

pavelst
  • 121
  • 1
  • 4
-2

Docker containers are stateless. If a container is shutdown or restarted, the contents of the container will be rolled back to its original state, meaning all the changes happened inside the container while it was running will be gone.

You can either save/export the edited image or use volumes.

Hy L
  • 522
  • 5
  • 11
  • 1
    The problem isn't the containers. I know that they are stateless. I'm having problem with the boot2docker environment, I lose every change I done as soon as I stop and start... I can solve parts of the problem by using the automounted file system on /Users but how do I persist changes to startup scripts, .profile etc... – Thomas Rambrant Jan 15 '15 at 07:02
  • as far as I know, /etc/hosts file in docker doesn't persist. If you made changes to /etc/hosts, the changes will be gone once you restart the container. I guess the same happens to .profile? – Hy L Jan 15 '15 at 18:26