The one about development environment

It’s time to do a side project, because my github account has been empty for too long. There is this idea that’s with me for quite some time. I don’t like to eat alone at the restaurant, but there are times when I don’t have a choice if I want to eat out. So I want to make web app, that makes it easy to find company to eat together at some place. I call it “Companeat

My technology stack will be:

  • Sails.js framework, because I want to write back-end in node.js
  • MongoDB database because I like how easy it is to implement with sails.js.
  • Front-end choice is still open for consideration. I am thinking Angular4 or React/Redux. This is new for me, so I am not really sure what are the upsides and downsides of both.
  • Docker, because I like things to be sandboxed and easy to manage.

For now I got my development environment ready for work. You can check how it looks on my github page here. This is how my workflow looked like (I won’t copy content of my files, because you can check them on github):

At first I created a project on github and cloned it. Then, inside project folder I made a Dockerfile with path: ./docker/dev/Dockerfile, and what I wanted to achieve was to have latest node, netcat installed, sails.js framework installed globally. Moreover I wanted default sails.js port to be exposed for other potential services.

At the end I wanted node modules to be installed and sails to be lifted (app to be started) at the end of container creation. This was the first tricky part.

I created shell executable file inside ./docker/dev/ path called with commands for installing node modules, creating log files and lifting the application. I copied the file inside container and executed (from the Dockerfile command), so when the container is ready it runs and it does what we told it to be done.

Now I had to write docker-compose.yml because I like to use docker-compose a lot. To be short: Every service is a stand-alone container, but when they are defined in one docker-compose they are linked to each other in a some sort of virtual network.

First service I named backend, gave it Dockerfile path so it knows the source from where it needs to be built. I made host (my computer) port 7331 to be connected to docker port 1337 (sails.js default port). I defined database volume to be shared between backend and mongo_db containers and gave my containers
-it flags as in docker -it container_name bash.

Second service is my database service. It is built from existing mongo image, that I found on docker hub. As I told I gave it shared volume with backend. The configuration of this service can change as the application progresses, but for now it’s hard to tell how to configure my database.

There will be probably third service with my front-end application side, but for now I will focus mostly on doing the back-end job, just a heads up so you won’t feel confused.

When you try to start a project yourself with nothing but my Dockerfile, and docker-compose.yml files, you carefree type docker-compose up -d to start your containers and DUM-DUM-DUUUM… you will end up with error message, one like this: 

This is because you are trying to lift an application, that hasn’t been created yet. From sails.js documentation you can read that you need to create new project before you try to lift it. This is the second tricky part. You need to go to your container. In my example it would be docker exec -ti backend bash* and from there you need to create your project. With my configuration the easiest way is to go to your root path (while still inside container of course) cd / and override /project folder with sails new project command. Remember that it needs to be empty! (You can see how I did that on the screenshot above). After that you can exit your container and you need to rebuild your container. The easiest way is to docker-compose up -d --build After that you should have your application up and running. You can check it at least both ways. First you can docker logs -f backend so you can see:

or you can go to http://localhost:7331/ and if you see this: 

you can start building your web application.

My article may be a little chaotic, I am still making my first steps in the blogosphere, so any feedback will be appreciated. Please comment, and if in any doubt or you need help with your programming struggles PM me. We can struggle together so you’ll feel less lonely 😉


*-i, –interactive=false Keep STDIN open even if not attached
-t, –tty=false Allocate a pseudo-TTY

Leave a Reply

Your email address will not be published. Required fields are marked *