4

I'm new to Docker and was wondering if it was possible (and a good idea) to develop within a docker container. I mean create a container, execute bash, install and configure everything I need and start developping inside the container.

The container becomes then my main machine (for CLI related works). When I'm on the go (or when I buy a new machine), I can just push the container, and pull it on my laptop.

This sort the problem of having to keep and synchronize your dotfile.

I haven't started using docker yet, so is it something realistic or to avoid (spacke disk problem and/or pull/push timing issue).

mb14
  • 22,276
  • 7
  • 60
  • 102
  • 1
    This blog post might be of some interest: http://nathanleclaire.com/blog/2014/07/12/10-docker-tips-and-tricks-that-will-make-you-sing-a-whale-song-of-joy/ – Adrian Mouat Feb 02 '15 at 12:55
  • 1
    I'm using x2go+xubuntu and x2go+xfce+debian/sid based docker containers for gui development and debugging when I need to use tools and libs which I can't or don't want to install directly - so it is not only for cli. – ISanych Feb 02 '15 at 13:53

3 Answers3

3

Yes. It is a good idea, with the correct set-up. You'll be running code as if it was a virtual machine.

The Dockerfile configurations to create a build system is not polished and will not expand shell variables, so pre-installing applications may be a bit tedious. On the other hand after building your own image to create new users and working environment, it won't be necessary to build it again, plus you can mount your own file system with the -v parameter of the run command, so you can have the files you are going to need both in your host and container machine. It's versatile.

> sudo docker run -t -i -v
/home/user_name/Workspace/project:/home/user_name/Workspace/myproject <container-ID>
Alex
  • 975
  • 10
  • 24
  • How do you deal with the user permissions issue during development? If you use `--user` to id yourself as the user on your host dev desktop then the container isn't run as root, and many commands fail (`whoami` -> `cannot find name for user ID 1000`, for example). If you add user ID 1000 to the container then it won't necessarily match someone elses system who's user ID is 2000. – David Parks Jul 20 '19 at 19:55
1

I'll play the contrarian and say it's a bad idea. I've done work where I've tried to keep a container "long running" and have modified it, but then accidentally lost it or deleted it.

In my opinion containers aren't meant to be long running VMs. They are just meant to be instances of an image. Start it, stop it, kill it, start it again.

As Alex mentioned, it's certainly possible, but in my opinion goes against the "Docker" way.

I'd rather use VirtualBox and Vagrant to create VMs to develop in.

ryan1234
  • 7,237
  • 6
  • 25
  • 36
  • 1
    Running container should not be modified, except for quick test purpose before the modification is codified outside or by modifying the host-mounted volume. If you follow this rule, there is absolutely no issue in "accidentally lost or deleted" container as you instantly recreate it anew. If you don't - then you probably don't follow the docker philosophy and other tool (vagrant) might suit your need better. – Mykola Gurov Feb 02 '15 at 21:18
  • Note that you have to purposely remove the container with `docker rm`. The contents (even modified) persist by default. Noted because I just didn't want people to think that losing data is the default. Still, I sympathize with _ryan1234_ because I almost always remove my non-running container out of habit. – Andy Feb 03 '15 at 00:50
  • I never mean to delete them and I never try to use containers as VMs. But you know, sometimes you get in there to try some things, forget what you did, it goes away, and pain. – ryan1234 Feb 03 '15 at 04:06
  • I can understand how that might happen and I can imagine that it is more common in certain development environments than others. For example, I develop web apps in PHP. My development container is derived from an Apache image which never changes. The code I'm editing is in a host directory mounted in the container. The Apache container could be deleted and re-run and it wouldn't affect anything. However, this only works because I have a set of supporting applications (Apache, etc.) which are not tightly coupled to my application. I can imagine that other environments might be different. – Kryten Feb 03 '15 at 22:44
  • Despite I commented about the possibility of duplicating volumes in the container, if (whatever the reason might be) you think your container may delete files from the shared volumes unexpectedly, you can always use the COPY command in the dockerfile to build your image. You have both options. – Alex Feb 04 '15 at 18:22
1

Docker container for development can be very handy. Depending on your stack and preferred IDE you might want to keep the editing part outside, at host, and mount the directory with the sources from host to the container instead, as per Alex's suggestion. If you do so, beware potential performance issue on macos x with boot2docker.

I would not expect much from the workflow with pushing the images to sync between dev environments. IMHO keeping Dockerfiles together with the code and synching by SCM means is more straightforward direction to start with. I also carry supporting Makefiles to build image(s) / run container(s) same place.

Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27