And a Whale Said Let There Be Docker Tools
August 15, 2015Every time I had to work on a new machine or I wanted to try a new technology, I used to install a lot of packages and libraries to prepare my development environment. I always struggled to manage dependencies and different versions of packages. That mostly worked for me but I had to go over this hustle everytime. Besides, after some time the machine I was working on used to get a bit slower.
And then there was Docker
I have been recently hearing about virtualization, Linux Containers, Docker, Vagrant, etc., but Docker became sort of the hype these days. I wanted to give it a try anyway specially after @cousine had recommended using Docker to me.
So I started this weekend by installing a new version of Elementary OS and Docker, and set up my dotfiles on my main development laptop.
You can install and use any of the available packages on your machine using Docker images from database servers to frameworks or tools like Nodejs or Jekyll. It’s also possible to create your own dockerized images. I installed different kinds of images for my local development
As Docker is often used for deployment and packaging dependencies, it could also be used for local development. This is about satisfying the perfectionist in me.
Example
I use Jekyll (now Hugo) to generate this blog.
Before Docker, I had to install a Ruby version manager such as rbenv, Ruby, RubyGems, and Jekyll
just to start blogging. But now all I do is just this:
1. Install Docker
It’s in the documentation.
2. Pull (Download) a Jekyll image from DockerHub:
I use this image. It does the job very well
$ docker pull grahamc/jekyll
3. Create a new blog:
$ docker run --rm -v "$PWD:/src" -p 4000:4000 grahamc/jekyll new my_blog
You may need to change your folder permissions if you didn’t add your user account to docker group
$ sudo chmod -R o+rw my_blog
4. Start the app:
Open a terminal in your blog directory and run Jekyll server
$ sudo docker run --rm -v "$PWD:/src" -p 4000:4000 grahamc/jekyll serve -H
0.0.0.0
Now if you open 0.0.0.0:4000
in a browser, you’ll find your blog
working just fine.
More Practical Example
I had a PHP web project for first time so I searched for PHP and Apache Docker images and luckily I found a Docker file that installs all the necessary packages and dependencies. I cannot exactly remember where I got it from besides I changed some lines in the original (anyway, here’s another one that installs XAMPP. I combined it with docker-compose to link the app to MySQL databse image. I run the app with a very simple command:
$ docker-compose up
and everything is working fine
You can find the full project along with Docker and docker-compose files here.