DEV Community

Cover image for How I replaced all my development binaries with Docker & Docker Compose
Amin
Amin

Posted on

How I replaced all my development binaries with Docker & Docker Compose

Funny story, It was not so long ago that I started using VSCode on my computer. Since then I really loved what Microsoft did with this software and this was also the time I started using TypeScript. They are really going in a good direction and I'm not seing Microsoft as the only giant company that just want to make some money but rather as a company that is trying to help the open-source community to thrive, while of course keeping their main goal. But that is not the topic of this post.

When I started using VSCode on my Archlinux distribution, I already had installed the Node.js binary in my operating system. But for some reason, the open-source version of VSCode was using a special version of Node.js called Node.js Carbon (I really don't know what was the differences between this and the original binary and didn't take the time to check). So obviously during the installation a conflict appeared saying that I needed to uninstall my nodejs and confirm the installation of the nodejs-lts-carbon version. At this time I was not worried that much and just hit ENTER until I get my VSCode installed.

But when I started updating some of my ongoing project, I noticed some errors I didn't have back in the time. And after some investigations I finally understood that this was my Node.js version that wasn't meeting the project's requirements. At first, I was sad because it meant that I had to uninstall VSCode, or use the pre-compiled version (that I didn't want to use). So I just kept on going with VIM and installed the latest version of Node.js back.

That is when someone talked to me about Docker. This is also when I started enjoying my development even more.

Docker allows you to create a containerized space where all installed binaries are separated from the outside world, meaning your own operating system. This means that you can have either a version of nodejs, nodejs-lts-carbon and whatever version you want, all at the same time and without changing your operating system from a bit, just by installing Docker. Of course since then I installed VSCode back and just used Node.js with Docker in all my projects. I though that it was all that I could do but I was wrong.

With time, I started gaining some experience about Docker and dicovered Docker Compose, which is like a scriptable version of Docker which allows you to automate most of the task you could do with Docker and write them inside a simple YAML file. This is really great for not having to write some Bash script to do this kind of task. It is really clear and standardized so that you can embed this file in your project and share it with your team. You'll have to installed another binary which is the Docker Compose binary. But in the end, if you are confortable enough, you can get rid of all of your development binaries and just use Docker with Docker Compose for anything really.

That is exactly what I did. I have no more web server, (Apache or NGINX) nor web development binaries like PHP or Node.js and others. Anytime I want to start a project I simply write a docker-compose.yaml file with all my requirements and start my project by running docker-compose up --detach to fire up all my containers.

This has some advantages. Let's say you want to test a website which is running PHP 5. If you wanted to test if you really need to append some changes to your source-code before upgrading your remote web server to PHP 7, you can just mount your website inside a Dockerized version of PHP 7 and test it in the fly. If you had to do this, you would want to install PHP 7 on your OS X, Windows or Linux operating system and maybe break some configuration you had for your Apache web server and start investigating this issue that would eventually lead you to use some dark tools that would mess your operating system even more.

version: "3"

services:
  php:
    image: php7:apache
    volumes:
      - ./www:/var/www/html
    ports:
      - 1234:80
$ docker-compose up --detach
$ curl http://localhost:1234
Hello from my website in PHP5!

That's it! I really used all you would use in real life for testing such case. Even if you do not know how Docker works, you must admit that it was a lot more easier than setting up a whole environment using MAMP or WAMP or [INSERT A WEB STACK HERE].

In my point of view, Docker coupled with Docker Compose is all about peace of mind, ease of development and a better portability for your project as it is available for all major operating systems whether it is OS X, Windows or GNU/Linux.

If you want to give Docker a try, check out the official website here. Let me know if you have some more question. Thanks for reading me and until next time!

Top comments (0)