Be a better front-end developer: use Docker 🐳
Hey Alice, are you:
- tired of having to install NodeJS on your PC?
- tired of your backend friends saying “Docker it’s cool”, but you are just a fucking frontend dev?
- tired of dealing with dependency conflicts?
- tired of being tired?
Docker is the solution, trust me!
But let’s be clear: I’m not here to show you how docker works.
The whole point here is:
You don’t need NodeJS on your pc to compile assets, you can use Docker
So, if you are a fronted dev tired of all of the JS nonsense, follow me in the rabbit hole.
One command to rule them all
If you just need to execute NodeJS in a heartbit (pun intended), here is the magic formula to write in the command line
$ docker run --rm -v $(pwd):/app -w /app node:latest npm install
And with few changes, you can easily:
- execute a Specific NodeJS version (eg. 9.11) edit the command with:
node:9.11
. - execute multiple commands in NodeJS simply using
/bin/bash -c
. - run a specific environment (prod | dev) adding
-e "NODE_ENV=production"
$ docker run --rm -e "NODE_ENV=production" -v $(pwd):/app -w /app node:9.11 /bin/bash -c "npm install && npm start"
Easy peasy, lemon squeezy.
This method is amazing if you just need to run some quick and dirty test and be ready to go in few minutes.
A more structured way: docker-compose.yml
What if you need to create something reusable and with some kind of persistency?
Docker Compose will help you on this task:
Docker Compose is the tool to define and run multiple Docker container.
Yeah, I know.. you don’t give a fuck about definitions. You are just a fucking frontend developer 🙌
Let me keep diving you into the rabbit hole, Alice.
Here you can see how I’ve added a docker-compose.yml file in my folder structure
Folder structureapp
├─ ...
├─ docker-compose.yml
└─ package.json
And this is the docker-compose.yml content
As you see, I’ve specified the specs I need in the .yml file instead of writing them in the command line. Now simply run
$ docker-compose run node npm install
to execute your Docker container.
Yes, Alice.
I’ve just Dockerized your fuckin ass, frontend dev!