Node.JS Docker Container Deployment

nodejs docker container in apiplugWith API Plug you can easily download your API as Docker containers instead of plain Node.JS source code.

Here is the how to deploy your Node.JS Docker container to your server.

[markdown]

##TL;DR
Fast forward version

– copy files to web server
– adjust db credentials if needed
– `docker build -t [yourapi] .`
– `docker run -d -p [yourport]:8080 [yourapi]`

[/markdown]

[markdown]


##Long Version

If you opted to use a Docker container; you can get your API up and running with these:

– Copy Files to Your Web Server
– UnZip / UnTar Files
– (optional) Update Database Credentials
– Build Docker Image
– Run Docker Image
Let’s look at each step closely.

##Copy Files to Your Webserver
You can use scp, FileZilla or your transfer method of choice. Our NodeJS package have it’s own web server so you can copy it anywhere you want.

##UnZip / UnTar Files
**Unzip**

`unzip yourfile.zip`

**UnTar**

`tar -zxvf yourfile.tar.gz`

##(Optional) Update Database Credentials

We are big on data privacy, so if you opted to upload your schema, you need to go inside `/databases/` and update your credentials

## Build Docker Image
We assume you already installed Docker in your system. If not [click here](https://docs.docker.com/installation/) to install Docker package.

When you unzip files, you’ll see a `DockerFile`. We’ve already taken care of default settings but you are welcome to customise it further.

Simply run
`docker build -t [yourapi] .` (don’t forget . at the end)

##Run Docker Image

Simply run

`docker run -d -p [yourport]:8080 [yourapi]`

– -d is for running your container in deamon mode
– -p is for mapping port of your choice into container
[/markdown]

Leave a comment

Leave a Reply

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