Docker Community Forums

Share and learn in the Docker community.

Persistent Development Environment using Docker

(Ruffsl) #1

I’d like some suggestions in using Docker as a Persistent Development Environment for various projects. Now I know chroots with schroot may be the more traditionally appropriate for this use case, but the majority of the projects I use are already well integrated into docker ecosystem, and I’m already more familiar with Docker CLI. I’d also like to be able to move or connect my dev environment around with docker’s virtual networking and all, so some service I tinker with won’t collide with my local network.

Currently I have a shell alias that launches the container and mounts all my workspaces/devices and such, located on my host. However, if I ever need to install some new small dev tool during the session, I end up a needing to remember to tack it onto the dockerfile build, or commit the container to a new image layer. In either case I end up a bunch of orphaned layers, or a monolithic image I have to collapse every once in a while.

Are there any convenient/appropriate ways of mounting a whole root system into a container? I see the docker-brew-ubuntu-core/ used for the official ubuntu image goes about something similar when building the image. However, I’d like start from an existing docker image rather than from starch image plus a root.tar.gz.

I was thinking of something like this:

  1. Starting a dummy container with the desired image,
  2. Use docker export to generate a .tar file from the container
  3. Extract the .tar to say a workspaces folder where I’d like to keep the persistent dev environment
  4. Start a new container from the same image but with the extracted tar folder mounted as / in the container
    docker run -it -v /workspaces/trusty:/ ubuntu

This although results in the flowing error:

docker: Error response from daemon: Invalid bind mount spec " /workspaces/trusty:/": Invalid specification: destination can't be '/' in ' /workspaces/trusty:/'.

I found a docker issue talking about a reciprocal of my needs, but I’m looking to mount in a / file system for the container, not the / from my host. Any suggestions to go about this with docker?

(Jeff Anderson) #2

Volumes simply aren’t allowed to be the / of a container.

I imagine that it would introduce lots of problems with the other things docker does.

Usually if you want a persistent development environment, you do a host mount of just your application’s code to a specific directory.

(Ruffsl) #3

Yes, this is what I do when my environment is stable, and the state of the preconfigured system is relatively detached from the persistent project files. However something like apt-get installing anything during runtime commonly ropes in a swath of dependencies that touch all sorts of directories.

I’ve had a successful venture in mounting all the sub root directories individually, taking care to omit the virtual filesystems /proc and /dev. I think a few other directories could safely be omitted too, such as /tmp, /mnt, /media, /run, /sys, and possibly parts of /var but I’ll have check. The only troubles are that the original file permissions are not maintained during export and extraction step above.