Friday, March 30, 2018

Dockerizing Your IDE

I have successfully created Docker images for my IDE (Vim with a few plugins and Linux tools) and here are the details of that journey in hope that it will help you do the same. If you don't want to read the details, feel free to jump straight to the Git repo with my dockerized IDE: https://github.com/maxzheng/ide

I started out with a Dockerfile that installs everything I needed and then mapped any persisted data from my macOS host. It seemed to work ok until I started to search my source code. The file system performance was fairly bad for a workspace with lots of big repos (apparently a known issue with host volumes that can't be fixed). And then there was an issue with mapping ports as --net=host doesn't work on Docker for macOS since it is running a VM, which just maps all the ports to the VM and not the macOS host. Finally, I couldn't find any way to run multiple services in the background to start a MySQL instance or run cron jobs -- maybe there is a way with initd scripts. So many problems, let's see how to fix them.

For the --net=host issue, there isn't much that can be done there, so I just statically opened any port that I needed using the -p flag.

For running MySQL, as each Dockerfile can only run one command when it starts, I decided to go along with the Docker best practice of creating a separate container dedicated to just running that. As there are MySQL images on Docker Hub, it turned out even easier. During this time, I also started looking into Docker Compose, and that made orchestrating the containers easy. Just write everything in a docker-compose.yaml that links the main IDE container with the MySQL container, and voila -- it builds on any changes and recreates all the containers if needed.

Instead of host volume mapping, I switched to a Docker volume. I didn't mind starting from a blank workspace as I was able to easily save all my pending changes in Github branches. Added the volume to the docker-compose.yaml file and Docker Compose does the rest.

Finally, for running cron job, I followed the same solution as MySQL by creating a separate container that runs all cronjobs. The workspace Docker volume is mapped in here to create ctags file for all the checkouts.

As for credentials, they remain on the macOS host and mapped using host volume. As they are small, there are no problems from the performance perspective.

With credentials mapped from host volume, workspace using Docker volume, and software with configurations in Dockerfiles, I am able to easily install, change, and revert software changes as they are versioned. If anything happens to my macOS, I only need to restore the credentials and then my full IDE is ready to use exactly like before. So easy and clean.

Without further ado, checkout my dockerized IDE at https://github.com/maxzheng/ide

This is part of the Technology blog series.

No comments:

Post a Comment