DEV Community

Cover image for Dockerize a Node.js app with VS Code

Dockerize a Node.js app with VS Code

Vladislav Guleaev on June 23, 2019

Hello dear coder, welcome to my tech articles series dedicated to Node.js and Docker. Hope you enjoy! Problem: You have never used Dock...
Collapse
 
bassemibrahim profile image
Bassem

Great article 👏, I remember wanting to dockerize a NodeJS server before. I managed to do it, but I struggled with the mysql database.

Ummm, Interesting topic for a future article maybe? Just saying 🖐️😂

Collapse
 
vguleaev profile image
Vladislav Guleaev

I plan to do the same but with MongoDb :) thank you for the feedback

Collapse
 
quinncuatro profile image
Henry Quinn

What exactly are you having problems with, @Bassem?

Collapse
 
bassemibrahim profile image
Bassem

I read about it online for a while first. Everyone was saying that it is better to have the database as a standalone image. So I got myself an Ubuntu MySQL dockerfile off the internet to create that DB image.

Now I have 2 images, one for the NodeJS server and another for MySql DB.

But, I can't connect them both. I even tried accessing the database using phpmyadmin from outside the docker container and failed.

In my docker-compose, I created a network, set both images on the same network. and added the links: - db:db to make the backend server depend on the database.

I know that the network is fine. because I have a third frontend server image and it can communicate with the backend successfully.

Thread Thread
 
quinncuatro profile image
Henry Quinn

For the PHPMyAdmin bit, are you exposing a port on the DB image? If you put two images on a Docker network like that, they just talk to everything on that network. You have to explicitly expose a port to have that container talk to anything "local" not on that network.

Thread Thread
 
quinncuatro profile image
Henry Quinn

For the Node -> DB bit, do you mind sharing your docker-compose.yaml and the connection string you're using in your Node container?

Collapse
 
pclewisnz profile image
pclewisnz

I failed at the second hurdle. Some pre-requisite knowledge that you have not explained. For a topic that appeared to be aimed at new docker user and using Windows system with VS Code as I have, I did not expect to be stumped so soon. I have reviewed a lot of tutorials and I have found ever one of them to be missing vital information (some are outright wrong). The effort you have gone to here looked promising so I have signed up to this site just to see if you still monitor this old topic and might have a response.
Here is the issue:
In the opening paragraph you write:
"Next command creates a new folder with name test-node-app, then creates npm package file and opens folder in VS Code.
mkdir test-node-app && cd test-node-app && npm init -y && code ."

Where do you type that? the syntax is wrong for powershell or command prompt and WSL doesn't know about npm so there must be some other pre-requsite knowledge or something missing in the Setup section.

Using powershell and appropriate commands to achieve the same as the linux style command line intends I have been able to continue. Perhaps though I am misisng something really important. Do you assume for example that the reader has already installed a unix VM and that they are running from that shell?

Collapse
 
quinncuatro profile image
Henry Quinn

Was there anything specific to VSCode in here?

Collapse
 
vguleaev profile image
Vladislav Guleaev

Only Docker Extension and command line

Collapse
 
quinncuatro profile image
Henry Quinn

Word, I was gonna say I love VSCode but nothing about the editor really does any Docker stuff for me besides the Quake terminal. I have the Docker extension but it doesn't really add anything for me.

Collapse
 
angusin profile image
Miguel Viñas • Edited

Thank you so much for the article!